unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#4234: allow xterm to detect the background color
@ 2009-08-22 17:15 ` Dan Nicolaescu
  2009-08-22 18:43   ` Andreas Schwab
  2009-12-20 16:01   ` bug#4234: marked as done (allow xterm to detect the background color) Emacs bug Tracking System
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Nicolaescu @ 2009-08-22 17:15 UTC (permalink / raw)
  To: bug-gnu-emacs


emacs/emacsclient -nw  running in an xterm set the frame background mode
to 'light.   
Not all users use the default white background, so they get the wrong
face colors. 
Newer xterms can tell what the background color is
(see http://permalink.gmane.org/gmane.emacs.devel/111270)

This patch implements reads the background color from xterm (iff it
supports the feature) and sets the background mode accordingly.

--- xterm.el.~1.62.~	2009-01-08 14:24:21.000000000 -0800
+++ xterm.el	2009-08-22 10:12:38.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,23 @@
 	    ;; 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))))
+	    ;; 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))))))
+	    (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






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

* bug#4234: allow xterm to detect the background color
  2009-08-22 17:15 ` bug#4234: allow xterm to detect the background color Dan Nicolaescu
@ 2009-08-22 18:43   ` Andreas Schwab
  2009-12-20 16:01   ` bug#4234: marked as done (allow xterm to detect the background color) Emacs bug Tracking System
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2009-08-22 18:43 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: bug-gnu-emacs, 4234

Dan Nicolaescu <dann@ics.uci.edu> writes:

> @@ -494,8 +493,23 @@
>  	    ;; NUMBER2 is the xterm version number, look for something
>  	    ;; greater than 216, the version when modifyOtherKeys was
>  	    ;; introduced.

You should move the comment down to where this version number is actually
tested.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#4234: marked as done (allow xterm to detect the background color)
  2009-08-22 17:15 ` bug#4234: allow xterm to detect the background color Dan Nicolaescu
  2009-08-22 18:43   ` Andreas Schwab
@ 2009-12-20 16:01   ` Emacs bug Tracking System
  1 sibling, 0 replies; 3+ messages in thread
From: Emacs bug Tracking System @ 2009-12-20 16:01 UTC (permalink / raw)
  To: Dan Nicolaescu

[-- Attachment #1: Type: text/plain, Size: 869 bytes --]

Your message dated Sun, 20 Dec 2009 08:00:07 -0800 (PST)
with message-id <200912201600.nBKG073w021776@godzilla.ics.uci.edu>
and subject line Re: bug#4234: allow xterm to detect the background color
has caused the Emacs bug report #4234,
regarding allow xterm to detect the background color
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact bug-gnu-emacs@gnu.org
immediately.)


-- 
4234: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=4234
Emacs Bug Tracking System
Contact bug-gnu-emacs@gnu.org with problems

[-- Attachment #2: Type: message/rfc822, Size: 5837 bytes --]

From: Dan Nicolaescu <dann@ics.uci.edu>
To: bug-gnu-emacs <bug-gnu-emacs@gnu.org>
Subject: allow xterm to detect the background color
Date: Sat, 22 Aug 2009 10:15:12 -0700 (PDT)
Message-ID: <200908221715.n7MHFCVA002498@godzilla.ics.uci.edu>


emacs/emacsclient -nw  running in an xterm set the frame background mode
to 'light.   
Not all users use the default white background, so they get the wrong
face colors. 
Newer xterms can tell what the background color is
(see http://permalink.gmane.org/gmane.emacs.devel/111270)

This patch implements reads the background color from xterm (iff it
supports the feature) and sets the background mode accordingly.

--- xterm.el.~1.62.~	2009-01-08 14:24:21.000000000 -0800
+++ xterm.el	2009-08-22 10:12:38.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,23 @@
 	    ;; 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))))
+	    ;; 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))))))
+	    (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



[-- Attachment #3: Type: message/rfc822, Size: 2660 bytes --]

From: Dan Nicolaescu <dann@ics.uci.edu>
To: 4234-done@emacsbugs.donarmstrong.com
Subject: Re: bug#4234: allow xterm to detect the background color
Date: Sun, 20 Dec 2009 08:00:07 -0800 (PST)
Message-ID: <200912201600.nBKG073w021776@godzilla.ics.uci.edu>

Patch is in.


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

end of thread, other threads:[~2009-12-20 16:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200912201600.nBKG073w021776@godzilla.ics.uci.edu>
2009-08-22 17:15 ` bug#4234: allow xterm to detect the background color Dan Nicolaescu
2009-08-22 18:43   ` Andreas Schwab
2009-12-20 16:01   ` bug#4234: marked as done (allow xterm to detect the background color) Emacs bug Tracking System

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).