diff options
Diffstat (limited to 'winsup/cygwin/fhandler_console.cc')
-rw-r--r-- | winsup/cygwin/fhandler_console.cc | 200 |
1 files changed, 61 insertions, 139 deletions
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 0dcd1262b..477265fe5 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -1,7 +1,7 @@ /* fhandler_console.cc Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. + 2006, 2008, 2009, 2010, 2011 Red Hat, Inc. This file is part of Cygwin. @@ -18,7 +18,6 @@ details. */ #include <winuser.h> #include <winnls.h> #include <ctype.h> -#include <sys/param.h> #include <sys/cygwin.h> #include <cygwin/kd.h> #include "cygerrno.h" @@ -36,15 +35,11 @@ details. */ #include <asm/socket.h> #include "sync.h" #include "child_info.h" -#include "cygwait.h" /* Don't make this bigger than NT_MAX_PATH as long as the temporary buffer is allocated using tmp_pathbuf!!! */ #define CONVERT_LIMIT NT_MAX_PATH -#define ALT_PRESSED (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) -#define CTRL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) - /* * Scroll the screen context. * x1, y1 - ul corner @@ -87,7 +82,7 @@ fhandler_console::console_state * fhandler_console::open_shared_console (HWND hw, HANDLE& h, bool& create) { wchar_t namebuf[(sizeof "XXXXXXXXXXXXXXXXXX-consNNNNNNNNNN")]; - __small_swprintf (namebuf, L"%S-cons%p", &cygheap->installation_key, hw); + __small_swprintf (namebuf, L"%S-cons%p", &installation_key, hw); shared_locations m = create ? SH_SHARED_CONSOLE : SH_JUSTOPEN; console_state *res = (console_state *) @@ -138,42 +133,34 @@ fhandler_console::set_unit () { bool created; fh_devices devset; - lock_ttys here; - HWND me; - fh_devices this_unit = dev (); - bool generic_console = this_unit == FH_CONIN || this_unit == FH_CONOUT; if (shared_console_info) { + fh_devices this_unit = dev (); fh_devices shared_unit = (fh_devices) shared_console_info->tty_min_state.getntty (); + created = false; devset = (shared_unit == this_unit || this_unit == FH_CONSOLE - || generic_console + || this_unit == FH_CONIN || this_unit == FH_CONOUT || this_unit == FH_TTY) ? shared_unit : FH_ERROR; - created = false; } - else if ((!generic_console && (myself->ctty != -1 && !iscons_dev (myself->ctty))) - || !(me = GetConsoleWindow ())) - devset = FH_ERROR; else { + HWND me = GetConsoleWindow (); created = true; shared_console_info = open_shared_console (me, cygheap->console_h, created); ProtectHandleINH (cygheap->console_h); if (created) - shared_console_info->tty_min_state.setntty (DEV_CONS_MAJOR, console_unit (me)); + { + lock_ttys here; + shared_console_info->tty_min_state.setntty (DEV_CONS_MAJOR, console_unit (me)); + } devset = (fh_devices) shared_console_info->tty_min_state.getntty (); } dev ().parse (devset); if (devset != FH_ERROR) pc.file_attributes (FILE_ATTRIBUTE_NORMAL); - else - { - set_io_handle (NULL); - set_output_handle (NULL); - created = false; - } return created; } @@ -308,6 +295,14 @@ fhandler_console::mouse_aware (MOUSE_EVENT_RECORD& mouse_event) return 0; } + /* Check whether adjusted mouse position can be reported */ + if (dev_state.dwMousePosition.X > 0xFF - ' ' - 1 + || dev_state.dwMousePosition.Y > 0xFF - ' ' - 1) + { + /* Mouse position out of reporting range */ + return 0; + } + return ((mouse_event.dwEventFlags == 0 || mouse_event.dwEventFlags == DOUBLE_CLICK) && mouse_event.dwButtonState != dev_state.dwLastButtonState) || mouse_event.dwEventFlags == MOUSE_WHEELED @@ -356,9 +351,9 @@ fhandler_console::read (void *pv, size_t& buflen) { case WAIT_OBJECT_0: break; - case WAIT_SIGNALED: + case WAIT_OBJECT_0 + 1: goto sig_exit; - case WAIT_CANCELED: + case WAIT_OBJECT_0 + 2: process_state.pop (); pthread::static_cancel_self (); /*NOTREACHED*/ @@ -417,6 +412,8 @@ fhandler_console::read (void *pv, size_t& buflen) #define ich (input_rec.Event.KeyEvent.uChar.AsciiChar) #define wch (input_rec.Event.KeyEvent.uChar.UnicodeChar) +#define ALT_PRESSED (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) +#define CTRL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) /* Ignore key up events, except for left alt events with non-zero character */ @@ -447,13 +444,12 @@ fhandler_console::read (void *pv, size_t& buflen) { char c = dev_state.backspace_keycode; nread = 0; - if (control_key_state & ALT_PRESSED) - { - if (dev_state.metabit) - c |= 0x80; - else - tmp[nread++] = '\e'; - } + if (control_key_state & ALT_PRESSED) { + if (dev_state.metabit) + c |= 0x80; + else + tmp[nread++] = '\e'; + } tmp[nread++] = c; tmp[nread] = 0; toadd = tmp; @@ -517,6 +513,8 @@ fhandler_console::read (void *pv, size_t& buflen) } #undef ich #undef wch +#undef ALT_PRESSED +#undef CTRL_PRESSED break; case MOUSE_EVENT: @@ -544,7 +542,6 @@ fhandler_console::read (void *pv, size_t& buflen) events at the same time. */ int b = 0; char sz[32]; - char mode6_term = 'M'; if (mouse_event.dwEventFlags == MOUSE_WHEELED) { @@ -568,7 +565,7 @@ fhandler_console::read (void *pv, size_t& buflen) { b = dev_state.last_button_code; } - else if (mouse_event.dwButtonState < dev_state.dwLastButtonState && !dev_state.ext_mouse_mode6) + else if (mouse_event.dwButtonState < dev_state.dwLastButtonState) { b = 3; strcpy (sz, "btn up"); @@ -589,10 +586,6 @@ fhandler_console::read (void *pv, size_t& buflen) strcpy (sz, "btn3 down"); } - if (dev_state.ext_mouse_mode6 /* distinguish release */ - && mouse_event.dwButtonState < dev_state.dwLastButtonState) - mode6_term = 'm'; - dev_state.last_button_code = b; if (mouse_event.dwEventFlags == MOUSE_MOVED) @@ -615,90 +608,34 @@ fhandler_console::read (void *pv, size_t& buflen) dev_state.nModifiers = 0; if (mouse_event.dwControlKeyState & SHIFT_PRESSED) dev_state.nModifiers |= 0x4; - if (mouse_event.dwControlKeyState & ALT_PRESSED) + if (mouse_event.dwControlKeyState & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED)) dev_state.nModifiers |= 0x8; - if (mouse_event.dwControlKeyState & CTRL_PRESSED) + if (mouse_event.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) dev_state.nModifiers |= 0x10; /* Indicate the modifiers */ b |= dev_state.nModifiers; /* We can now create the code. */ - if (dev_state.ext_mouse_mode6) - { - __small_sprintf (tmp, "\033[<%d;%d;%d%c", b, - dev_state.dwMousePosition.X + 1, - dev_state.dwMousePosition.Y + 1, - mode6_term); - nread = strlen (tmp); - } - else if (dev_state.ext_mouse_mode15) - { - __small_sprintf (tmp, "\033[%d;%d;%dM", b + 32, - dev_state.dwMousePosition.X + 1, - dev_state.dwMousePosition.Y + 1); - nread = strlen (tmp); - } - else if (dev_state.ext_mouse_mode5) - { - unsigned int xcode = dev_state.dwMousePosition.X + ' ' + 1; - unsigned int ycode = dev_state.dwMousePosition.Y + ' ' + 1; - - __small_sprintf (tmp, "\033[M%c", b + ' '); - nread = 4; - /* the neat nested encoding function of mintty - does not compile in g++, so let's unfold it: */ - if (xcode < 0x80) - tmp [nread++] = xcode; - else if (xcode < 0x800) - { - tmp [nread++] = 0xC0 + (xcode >> 6); - tmp [nread++] = 0x80 + (xcode & 0x3F); - } - else - tmp [nread++] = 0; - if (ycode < 0x80) - tmp [nread++] = ycode; - else if (ycode < 0x800) - { - tmp [nread++] = 0xC0 + (ycode >> 6); - tmp [nread++] = 0x80 + (ycode & 0x3F); - } - else - tmp [nread++] = 0; - } - else - { - unsigned int xcode = dev_state.dwMousePosition.X + ' ' + 1; - unsigned int ycode = dev_state.dwMousePosition.Y + ' ' + 1; - if (xcode >= 256) - xcode = 0; - if (ycode >= 256) - ycode = 0; - __small_sprintf (tmp, "\033[M%c%c%c", b + ' ', - xcode, ycode); - nread = 6; /* tmp may contain NUL bytes */ - } - syscall_printf ("mouse: %s at (%d,%d)", sz, - dev_state.dwMousePosition.X, - dev_state.dwMousePosition.Y); + sprintf (tmp, "\033[M%c%c%c", b + ' ', dev_state.dwMousePosition.X + ' ' + 1, dev_state.dwMousePosition.Y + ' ' + 1); + syscall_printf ("mouse: %s at (%d,%d)", sz, dev_state.dwMousePosition.X, dev_state.dwMousePosition.Y); toadd = tmp; + nread = 6; } } break; case FOCUS_EVENT: - if (dev_state.use_focus) - { - if (input_rec.Event.FocusEvent.bSetFocus) - __small_sprintf (tmp, "\033[I"); - else - __small_sprintf (tmp, "\033[O"); - - toadd = tmp; - nread = 3; - } + if (dev_state.use_focus) { + if (input_rec.Event.FocusEvent.bSetFocus) + sprintf (tmp, "\033[I"); + else + sprintf (tmp, "\033[O"); + + toadd = tmp; + nread = 3; + } break; case WINDOW_BUFFER_SIZE_EVENT: @@ -822,9 +759,7 @@ fhandler_console::scroll_screen (int x1, int y1, int x2, int y2, int xn, int yn) int fhandler_console::dup (fhandler_base *child, int flags) { - /* See comments in fhandler_pty_slave::dup */ - if (myself->ctty != -2) - myself->set_ctty (this, flags); + myself->set_ctty (this, flags); return 0; } @@ -892,9 +827,9 @@ fhandler_console::open (int flags, mode_t) void fhandler_console::open_setup (int flags) { + cygheap->manage_console_count ("fhandler_console::open", 1); set_flags ((flags & ~O_TEXT) | O_BINARY); - if (myself->set_ctty (this, flags) && !myself->cygstarted) - init_console_handler (true); + myself->set_ctty (this, flags); } int @@ -903,7 +838,7 @@ fhandler_console::close () CloseHandle (get_io_handle ()); CloseHandle (get_output_handle ()); if (!have_execed) - free_console (); + cygheap->manage_console_count ("fhandler_console::close", -1); return 0; } @@ -1571,30 +1506,22 @@ fhandler_console::char_command (char c) case 1000: /* Mouse tracking */ dev_state.use_mouse = (c == 'h') ? 1 : 0; + syscall_printf ("mouse support set to mode %d", dev_state.use_mouse); break; case 1002: /* Mouse button event tracking */ dev_state.use_mouse = (c == 'h') ? 2 : 0; + syscall_printf ("mouse support set to mode %d", dev_state.use_mouse); break; case 1003: /* Mouse any event tracking */ dev_state.use_mouse = (c == 'h') ? 3 : 0; + syscall_printf ("mouse support set to mode %d", dev_state.use_mouse); break; case 1004: /* Focus in/out event reporting */ dev_state.use_focus = (c == 'h') ? true : false; - break; - - case 1005: /* Extended mouse mode */ - dev_state.ext_mouse_mode5 = c == 'h'; - break; - - case 1006: /* SGR extended mouse mode */ - dev_state.ext_mouse_mode6 = c == 'h'; - break; - - case 1015: /* Urxvt extended mouse mode */ - dev_state.ext_mouse_mode15 = c == 'h'; + syscall_printf ("focus reporting set to %d", dev_state.use_focus); break; case 2000: /* Raw keyboard mode */ @@ -1811,7 +1738,7 @@ fhandler_console::write_normal (const unsigned char *src, if (trunc_buf.len) { const unsigned char *nfound; - int cp_len = MIN (end - src, 4 - trunc_buf.len); + int cp_len = min (end - src, 4 - trunc_buf.len); memcpy (trunc_buf.buf + trunc_buf.len, src, cp_len); memset (&ps, 0, sizeof ps); switch (ret = f_mbtowc (_REENT, NULL, (const char *) trunc_buf.buf, @@ -2012,7 +1939,8 @@ fhandler_console::write (const void *vsrc, size_t len) while (src < end) { - paranoid_printf ("char %0c state is %d", *src, dev_state.state_); + debug_printf ("at %d(%c) state is %d", *src, isprint (*src) ? *src : ' ', + dev_state.state_); switch (dev_state.state_) { case normal: @@ -2223,13 +2151,15 @@ get_nonascii_key (INPUT_RECORD& input_rec, char *tmp) int modifier_index = NORMAL; if (input_rec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) modifier_index = SHIFT; - if (input_rec.Event.KeyEvent.dwControlKeyState & CTRL_PRESSED) + if (input_rec.Event.KeyEvent.dwControlKeyState & + (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) modifier_index += CONTROL; for (int i = 0; keytable[i].vk; i++) if (input_rec.Event.KeyEvent.wVirtualKeyCode == keytable[i].vk) { - if ((input_rec.Event.KeyEvent.dwControlKeyState & ALT_PRESSED) + if ((input_rec.Event.KeyEvent.dwControlKeyState & + (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) && keytable[i].val[modifier_index] != NULL) { /* Generic ESC prefixing if Alt is pressed */ tmp[0] = '\033'; @@ -2418,19 +2348,11 @@ fhandler_console::create_invisible_console_workaround () return invisible_console = true; } -void -fhandler_console::free_console () -{ - BOOL res = FreeConsole (); - debug_printf ("freed console, res %d", res); - init_console_handler (false); -} - bool fhandler_console::need_invisible () { BOOL b = false; - if (exists ()) + if (GetConsoleCP ()) invisible_console = false; else { |