Subject: Re: bug#29716: 25.1; Wrong brackground-mode on gnome-terminal

From: Noam Postavsky <[email-masked]>
Date: Thu, 14 Dec 2017 21:47:45 -0500

tags 29716 + patch
quit

semente <[email-masked]> writes:

> On gnome-terminal 3.22.2 (Debian Stretch), for some reason, Emacs is
> setting the background-mode to light when I'm running a dark
> background. On xterm or ttys it works fine.

> $ printf '\e[>0c'
> 1;4601;0c
> $ printf '\e]11;?\e\'
> 11;rgb:2323/2727/2929
> $ echo $TERM
> xterm-256color

I think the attached should do the trick then.  There are two other
xterm features that Emacs tries to use based on version number; I'm not
sure how to test if your version of gnome-terminal supports them or not
though (so I played it safe in the patch and use the query background
feature only).

    (defun xterm--version-handler ()
      ...
        ;; If version is 216 (the version when modifyOtherKeys was
        ;; introduced) or higher, initialize the
        ;; modifyOtherKeys support.
        (when (>= version 216)
          (xterm--init-modify-other-keys))
        ;; In version 203 support for accessing the X selection was
        ;; added.  Hterm reports itself as version 256 and supports it
        ;; as well.  gnome-terminal doesn't and is excluded by this
        ;; test.
        (when (>= version 203)
          ;; Most xterms seem to have it disabled by default, and if it's
          ;; disabled, C-y will incur a timeout, so we only use it if the user
          ;; explicitly requests it.
          ;;(xterm--init-activate-get-selection)
          (xterm--init-activate-set-selection))...)

>From 34b6835f7581fb19f67fe134eab0b536af003dfa Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Thu, 14 Dec 2017 21:42:56 -0500
Subject: [PATCH v1] Query background for gnome terminal version 3.22
 (Bug#29716)

* lisp/term/xterm.el (xterm--version-handler): Use
xterm--report-background-handler for terminals reporting minor version
4000 and above.
---
 lisp/term/xterm.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index 4f79703833..df224757f9 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -670,9 +670,14 @@ xterm--version-handler
         (when (and (> version 2000) (equal (match-string 1 str) "1"))
           ;; Hack attack!  bug#16988: gnome-terminal reports "1;NNNN;0"
           ;; with a large NNNN but is based on a rather old xterm code.
-          ;; Gnome terminal 3.6.1 reports 1;3406;0
           ;; Gnome terminal 2.32.1 reports 1;2802;0
-          (setq version 200))
+          ;; Gnome terminal 3.6.1 reports 1;3406;0
+          (setq version 200)
+          ;; Gnome terminal 3.22.2 reports 1;4601;0 and *does* support
+          ;; background color querying (Bug#29716).
+          (when (> version 4000)
+            (xterm--query "\e]11;?\e\\"
+                          '(("\e]11;" .  xterm--report-background-handler)))))
         (when (equal (match-string 1 str) "83")
           ;; `screen' (which returns 83;40003;0) seems to also lack support for
           ;; some of these (bug#17607, bug#20356).
-- 
2.11.0