]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/win32con/win_driver.c
ncurses 6.5 - patch 20240519
[ncurses.git] / ncurses / win32con / win_driver.c
index 9822f125898baa167ebf291d78f015fd64366317..2425b3a44ce6f21eb2261d2a73a2cc4bf64b60ee 100644 (file)
@@ -55,7 +55,9 @@
 
 #define CUR TerminalType(my_term).
 
-MODULE_ID("$Id: win_driver.c,v 1.70 2023/02/12 00:31:33 tom Exp $")
+#define CONTROL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
+
+MODULE_ID("$Id: win_driver.c,v 1.74 2023/09/16 16:27:44 tom Exp $")
 
 #define TypeAlloca(type,count) (type*) _alloca(sizeof(type) * (size_t) (count))
 
@@ -82,33 +84,34 @@ static bool okConsoleHandle(TERMINAL_CONTROL_BLOCK *);
 #define write_screen WriteConsoleOutput
 #define read_screen  ReadConsoleOutput
 #endif
-
+/* *INDENT-OFF* */
 static const LONG keylist[] =
 {
-    GenMap(VK_PRIOR, KEY_PPAGE),
-    GenMap(VK_NEXT, KEY_NPAGE),
-    GenMap(VK_END, KEY_END),
-    GenMap(VK_HOME, KEY_HOME),
-    GenMap(VK_LEFT, KEY_LEFT),
-    GenMap(VK_UP, KEY_UP),
-    GenMap(VK_RIGHT, KEY_RIGHT),
-    GenMap(VK_DOWN, KEY_DOWN),
+    GenMap(VK_PRIOR,  KEY_PPAGE),
+    GenMap(VK_NEXT,   KEY_NPAGE),
+    GenMap(VK_END,    KEY_END),
+    GenMap(VK_HOME,   KEY_HOME),
+    GenMap(VK_LEFT,   KEY_LEFT),
+    GenMap(VK_UP,     KEY_UP),
+    GenMap(VK_RIGHT,  KEY_RIGHT),
+    GenMap(VK_DOWN,   KEY_DOWN),
     GenMap(VK_DELETE, KEY_DC),
     GenMap(VK_INSERT, KEY_IC)
 };
 static const LONG ansi_keys[] =
 {
-    GenMap(VK_PRIOR, 'I'),
-    GenMap(VK_NEXT, 'Q'),
-    GenMap(VK_END, 'O'),
-    GenMap(VK_HOME, 'H'),
-    GenMap(VK_LEFT, 'K'),
-    GenMap(VK_UP, 'H'),
-    GenMap(VK_RIGHT, 'M'),
-    GenMap(VK_DOWN, 'P'),
+    GenMap(VK_PRIOR,  'I'),
+    GenMap(VK_NEXT,   'Q'),
+    GenMap(VK_END,    'O'),
+    GenMap(VK_HOME,   'H'),
+    GenMap(VK_LEFT,   'K'),
+    GenMap(VK_UP,     'H'),
+    GenMap(VK_RIGHT,  'M'),
+    GenMap(VK_DOWN,   'P'),
     GenMap(VK_DELETE, 'S'),
     GenMap(VK_INSERT, 'R')
 };
+/* *INDENT-ON* */
 #define N_INI ((int)array_length(keylist))
 #define FKEYS 24
 #define MAPSIZE (FKEYS + N_INI)
@@ -123,7 +126,6 @@ static struct {
     BOOL buffered;
     BOOL window_only;
     BOOL progMode;
-    BOOL isMinTTY;
     BOOL isTermInfoConsole;
     HANDLE out;
     HANDLE inp;
@@ -486,7 +488,7 @@ wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
 
        Width = screen_columns(sp);
        Height = screen_lines(sp);
-       nonempty = min(Height, NewScreen(sp)->_maxy + 1);
+       nonempty = Min(Height, NewScreen(sp)->_maxy + 1);
 
        T(("... %dx%d clear cur:%d new:%d",
           Height, Width,
@@ -610,6 +612,12 @@ wcon_doupdate(TERMINAL_CONTROL_BLOCK * TCB)
     returnCode(result);
 }
 
+#ifdef __MING32__
+#define SysISATTY(fd) _isatty(fd)
+#else
+#define SysISATTY(fd) isatty(fd)
+#endif
+
 static bool
 wcon_CanHandle(TERMINAL_CONTROL_BLOCK * TCB,
               const char *tname,
@@ -641,6 +649,8 @@ wcon_CanHandle(TERMINAL_CONTROL_BLOCK * TCB,
        }
     } else if (tname != 0 && stricmp(tname, "unknown") == 0) {
        code = TRUE;
+    } else if (SysISATTY(TCB->term.Filedes)) {
+       code = TRUE;
     }
 
     /*
@@ -1476,10 +1486,10 @@ Adjust(int milliseconds, int diff)
                     FROM_LEFT_4TH_BUTTON_PRESSED | \
                     RIGHTMOST_BUTTON_PRESSED)
 
-static int
+static mmask_t
 decode_mouse(SCREEN *sp, int mask)
 {
-    int result = 0;
+    mmask_t result = 0;
 
     (void) sp;
     assert(sp && console_initialized);
@@ -1668,14 +1678,14 @@ handle_mouse(SCREEN *sp, MOUSE_EVENT_RECORD mer)
 
        if (sp->_drv_mouse_new_buttons) {
 
-           work.bstate |= (mmask_t) decode_mouse(sp, sp->_drv_mouse_new_buttons);
+           work.bstate |= decode_mouse(sp, sp->_drv_mouse_new_buttons);
 
        } else {
 
            /* cf: BUTTON_PRESSED, BUTTON_RELEASED */
-           work.bstate |= (mmask_t) (decode_mouse(sp,
-                                                  sp->_drv_mouse_old_buttons)
-                                     >> 1);
+           work.bstate |= (decode_mouse(sp,
+                                        sp->_drv_mouse_old_buttons)
+                           >> 1);
 
            result = TRUE;
        }
@@ -1957,11 +1967,6 @@ _nc_mingw_isatty(int fd)
 {
     int result = 0;
 
-#ifdef __MING32__
-#define SysISATTY(fd) _isatty(fd)
-#else
-#define SysISATTY(fd) isatty(fd)
-#endif
     if (SysISATTY(fd)) {
        result = 1;
     } else {
@@ -2126,9 +2131,9 @@ _nc_mingw_console_read(
                *buf = (int) inp_rec.Event.KeyEvent.uChar.AsciiChar;
                vk = inp_rec.Event.KeyEvent.wVirtualKeyCode;
                /*
-                * There are 24 virtual function-keys, and typically
-                * 12 function-keys on a keyboard.  Use the shift-modifier
-                * to provide the remaining 12 keys.
+                * There are 24 virtual function-keys (defined in winuser.h),
+                * and typically 12 function-keys on a keyboard.  Use the
+                * shift-modifier to provide the remaining keys.
                 */
                if (vk >= VK_F1 && vk <= VK_F12) {
                    if (inp_rec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) {
@@ -2145,6 +2150,11 @@ _nc_mingw_console_read(
                        ungetch('\0');
                        *buf = AnsiKey(vk);
                    }
+               } else if (vk == VK_BACK) {
+                   if (!(inp_rec.Event.KeyEvent.dwControlKeyState
+                         & (SHIFT_PRESSED | CONTROL_PRESSED))) {
+                       *buf = KEY_BACKSPACE;
+                   }
                }
                break;
            } else if (inp_rec.EventType == MOUSE_EVENT) {
@@ -2172,9 +2182,6 @@ InitConsole(void)
        BOOL b;
 
        START_TRACE();
-       if (_nc_mingw_isatty(0)) {
-           CON.isMinTTY = TRUE;
-       }
 
        for (i = 0; i < (N_INI + FKEYS); i++) {
            if (i < N_INI) {