* lisp/term/w32console.el (get-screen-color): Declare.
[bpt/emacs.git] / lisp / term / w32console.el
index 6072613..cd5aed3 100644 (file)
@@ -46,6 +46,7 @@
 "A list of VGA console colors, their indices and 16-bit RGB values.")
 
 (declare-function x-setup-function-keys "term/common-win" (frame))
+(declare-function get-screen-color "w32console.c" ())
 
 (defun terminal-init-w32console ()
   "Terminal initialization function for w32 console."
       (setq colors (cdr colors)
             color (car colors))))
   (clear-face-cache)
+  ;; Figure out what are the colors of the console window, and set up
+  ;; the background-mode correspondingly.
+  (let* ((screen-color (get-screen-color))
+        (bg (cadr screen-color))
+        (descr (tty-color-by-index bg))
+        r g b bg-mode)
+    (setq r (nth 2 descr)
+         g (nth 3 descr)
+         b (nth 4 descr))
+    (if (< (+ r g b) (* .6 (+ 65535 65535 65535)))
+       (setq bg-mode 'dark)
+      (setq bg-mode 'light))
+    (set-terminal-parameter nil 'background-mode bg-mode))
   (tty-set-up-initial-frame-faces)
   (run-hooks 'terminal-init-w32-hook))