public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Add code to restore console mode on close. Date: Tue, 14 Jan 2020 16:31:00 -0000 [thread overview] Message-ID: <20200114163104.129860.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=783eaa888feaf4f76df3d3449e29aa20aa78c802 commit 783eaa888feaf4f76df3d3449e29aa20aa78c802 Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Thu Jan 2 22:17:16 2020 +0900 Cygwin: console: Add code to restore console mode on close. - The console with 24bit color support has a problem that console mode is changed if cygwin process is executed in cmd.exe which started in cygwin shell. For example, cursor keys become not working if bash -> cmd -> true are executed in this order. This patch fixes the issue. Diff: --- winsup/cygwin/fhandler_console.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 337331b..b3f2cb6 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -53,6 +53,9 @@ fhandler_console::console_state NO_COPY *fhandler_console::shared_console_info; bool NO_COPY fhandler_console::invisible_console; +static DWORD orig_conin_mode = (DWORD) -1; +static DWORD orig_conout_mode = (DWORD) -1; + static void beep () { @@ -1010,6 +1013,11 @@ fhandler_console::open (int flags, mode_t) get_ttyp ()->rstcons (false); set_open_status (); + if (orig_conin_mode == (DWORD) -1) + GetConsoleMode (get_handle (), &orig_conin_mode); + if (orig_conout_mode == (DWORD) -1) + GetConsoleMode (get_output_handle (), &orig_conout_mode); + if (getpid () == con.owner && wincap.has_con_24bit_colors ()) { DWORD dwMode; @@ -1079,6 +1087,19 @@ fhandler_console::close () SetConsoleMode (get_output_handle (), dwMode); } + /* Restore console mode if this is the last closure. */ + OBJECT_BASIC_INFORMATION obi; + NTSTATUS status; + status = NtQueryObject (get_handle (), ObjectBasicInformation, + &obi, sizeof obi, NULL); + if (NT_SUCCESS (status) && obi.HandleCount == 1) + { + if (orig_conin_mode != (DWORD) -1) + SetConsoleMode (get_handle (), orig_conin_mode); + if (orig_conout_mode != (DWORD) -1) + SetConsoleMode (get_handle (), orig_conout_mode); + } + CloseHandle (get_handle ()); CloseHandle (get_output_handle ());
reply other threads:[~2020-01-14 16:31 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200114163104.129860.qmail@sourceware.org \ --to=corinna@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).