[newlib-cygwin/cygwin-3_6-branch] Cygwin: pty: Omit CSI?1004h/l from pseudo console output

Takashi Yano tyan0@sourceware.org
Wed Mar 25 21:32:12 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b501f7033e13232956fd947b960f8d684de8a074

commit b501f7033e13232956fd947b960f8d684de8a074
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Thu Mar 26 06:30:25 2026 +0900

    Cygwin: pty: Omit CSI?1004h/l from pseudo console output
    
    "CSI?1004h" is the sequence that enables focus event report. This
    can be handle correctly by pseudo console, however, if the pty
    input is not connected to pseudo console, the focus event responses
    such as "CSI I/O" are sent to the foreground process. Due to this,
    `cat` receives these responses unexpectedly in the command below.
    
    $ cmd &
    $ cat
    
    This seems to happen since Windows 11.
    
    To avoid this, this patch removes "CSI?1004h/l" from pseudo console
    output.
    
    Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    Reviewed-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/fhandler/pty.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index 8f860cfb5..c900682da 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2738,6 +2738,7 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
 	      state = 0;
 
 	  /* Remove CSI ? 9001 h/l (win32-input-mode) */
+	  /* Remove CSI ? 1004 h/l (focus report) */
 	  int arg = 0;
 	  state = 0;
 	  for (DWORD i = 0; i < rlen; i++)
@@ -2757,7 +2758,7 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
 	      arg = arg * 10 + (outbuf[i] - '0');
 	    else if (state == 3 && outbuf[i] == ';')
 	      arg = 0;
-	    else if (state == 3 && arg == 9001
+	    else if (state == 3 && (arg == 9001 || arg == 1004)
 		     && (outbuf[i] == 'h' || outbuf[i] == 'l'))
 	      {
 		memmove (&outbuf[start_at], &outbuf[i+1], rlen-i-1);


More information about the Cygwin-cvs mailing list