Karsten Hopp c7dbd3
To: vim_dev@googlegroups.com
Karsten Hopp c7dbd3
Subject: Patch 7.4.137
Karsten Hopp c7dbd3
Fcc: outbox
Karsten Hopp c7dbd3
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp c7dbd3
Mime-Version: 1.0
Karsten Hopp c7dbd3
Content-Type: text/plain; charset=UTF-8
Karsten Hopp c7dbd3
Content-Transfer-Encoding: 8bit
Karsten Hopp c7dbd3
------------
Karsten Hopp c7dbd3
Karsten Hopp c7dbd3
Patch 7.4.137
Karsten Hopp c7dbd3
Problem:    Cannot use IME with Windows 8 console.
Karsten Hopp c7dbd3
Solution:   Change the user of ReadConsoleInput() and PeekConsoleInput().
Karsten Hopp c7dbd3
	    (Nobuhiro Takasaki)
Karsten Hopp c7dbd3
Files:	    src/os_win32.c
Karsten Hopp c7dbd3
Karsten Hopp c7dbd3
Karsten Hopp c7dbd3
*** ../vim-7.4.136/src/os_win32.c	2014-01-10 13:05:12.000000000 +0100
Karsten Hopp c7dbd3
--- src/os_win32.c	2014-01-10 13:42:19.000000000 +0100
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 232,237 ****
Karsten Hopp c7dbd3
--- 232,306 ----
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  static char_u *exe_path = NULL;
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
+ /*
Karsten Hopp c7dbd3
+  * Version of ReadConsoleInput() that works with IME.
Karsten Hopp c7dbd3
+  */
Karsten Hopp c7dbd3
+     static BOOL
Karsten Hopp c7dbd3
+ read_console_input(
Karsten Hopp c7dbd3
+     HANDLE hConsoleInput,
Karsten Hopp c7dbd3
+     PINPUT_RECORD lpBuffer,
Karsten Hopp c7dbd3
+     DWORD nLength,
Karsten Hopp c7dbd3
+     LPDWORD lpNumberOfEventsRead)
Karsten Hopp c7dbd3
+ {
Karsten Hopp c7dbd3
+     enum
Karsten Hopp c7dbd3
+     {
Karsten Hopp c7dbd3
+ 	IRSIZE = 10, /* rough value */
Karsten Hopp c7dbd3
+     };
Karsten Hopp c7dbd3
+     static INPUT_RECORD irCache[IRSIZE];
Karsten Hopp c7dbd3
+     static DWORD s_dwIndex = 0;
Karsten Hopp c7dbd3
+     static DWORD s_dwMax = 0;
Karsten Hopp c7dbd3
+ 
Karsten Hopp c7dbd3
+     if (hConsoleInput == NULL || lpBuffer == NULL)
Karsten Hopp c7dbd3
+ 	return ReadConsoleInput(hConsoleInput, lpBuffer, nLength,
Karsten Hopp c7dbd3
+ 							lpNumberOfEventsRead);
Karsten Hopp c7dbd3
+ 
Karsten Hopp c7dbd3
+     if (nLength == -1)
Karsten Hopp c7dbd3
+     {
Karsten Hopp c7dbd3
+ 	if (s_dwMax == 0)
Karsten Hopp c7dbd3
+ 	{
Karsten Hopp c7dbd3
+ 	    PeekConsoleInput(hConsoleInput, lpBuffer, 1, lpNumberOfEventsRead);
Karsten Hopp c7dbd3
+ 	    if (*lpNumberOfEventsRead == 0)
Karsten Hopp c7dbd3
+ 		return FALSE;
Karsten Hopp c7dbd3
+ 	    ReadConsoleInput(hConsoleInput, irCache, IRSIZE, &s_dwMax);
Karsten Hopp c7dbd3
+ 	    s_dwIndex = 0;
Karsten Hopp c7dbd3
+ 	}
Karsten Hopp c7dbd3
+ 	((PINPUT_RECORD)lpBuffer)[0] = irCache[s_dwIndex];
Karsten Hopp c7dbd3
+ 	*lpNumberOfEventsRead = 1;
Karsten Hopp c7dbd3
+ 	return TRUE;
Karsten Hopp c7dbd3
+     }
Karsten Hopp c7dbd3
+ 
Karsten Hopp c7dbd3
+     if (s_dwMax == 0)
Karsten Hopp c7dbd3
+     {
Karsten Hopp c7dbd3
+ 	ReadConsoleInput(hConsoleInput, irCache, IRSIZE, &s_dwMax);
Karsten Hopp c7dbd3
+ 	s_dwIndex = 0;
Karsten Hopp c7dbd3
+ 	if (s_dwMax == 0)
Karsten Hopp c7dbd3
+ 	{
Karsten Hopp c7dbd3
+ 	    *lpNumberOfEventsRead = 0;
Karsten Hopp c7dbd3
+ 	    return FALSE;
Karsten Hopp c7dbd3
+ 	}
Karsten Hopp c7dbd3
+     }
Karsten Hopp c7dbd3
+ 
Karsten Hopp c7dbd3
+     ((PINPUT_RECORD)lpBuffer)[0] = irCache[s_dwIndex];
Karsten Hopp c7dbd3
+     if (++s_dwIndex == s_dwMax)
Karsten Hopp c7dbd3
+ 	s_dwMax = 0;
Karsten Hopp c7dbd3
+     *lpNumberOfEventsRead = 1;
Karsten Hopp c7dbd3
+     return TRUE;
Karsten Hopp c7dbd3
+ }
Karsten Hopp c7dbd3
+ 
Karsten Hopp c7dbd3
+ /*
Karsten Hopp c7dbd3
+  * Version of PeekConsoleInput() that works with IME.
Karsten Hopp c7dbd3
+  */
Karsten Hopp c7dbd3
+     static BOOL
Karsten Hopp c7dbd3
+ peek_console_input(
Karsten Hopp c7dbd3
+     HANDLE hConsoleInput,
Karsten Hopp c7dbd3
+     PINPUT_RECORD lpBuffer,
Karsten Hopp c7dbd3
+     DWORD nLength,
Karsten Hopp c7dbd3
+     LPDWORD lpNumberOfEventsRead)
Karsten Hopp c7dbd3
+ {
Karsten Hopp c7dbd3
+     return read_console_input(hConsoleInput, lpBuffer, -1,
Karsten Hopp c7dbd3
+ 							lpNumberOfEventsRead);
Karsten Hopp c7dbd3
+ }
Karsten Hopp c7dbd3
+ 
Karsten Hopp c7dbd3
      static void
Karsten Hopp c7dbd3
  get_exe_name(void)
Karsten Hopp c7dbd3
  {
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 1117,1123 ****
Karsten Hopp c7dbd3
  			INPUT_RECORD ir;
Karsten Hopp c7dbd3
  			MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent;
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
! 			PeekConsoleInput(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  			if (cRecords == 0 || ir.EventType != MOUSE_EVENT
Karsten Hopp c7dbd3
  				|| !(pmer2->dwButtonState & LEFT_RIGHT))
Karsten Hopp c7dbd3
--- 1186,1192 ----
Karsten Hopp c7dbd3
  			INPUT_RECORD ir;
Karsten Hopp c7dbd3
  			MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent;
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
! 			peek_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  			if (cRecords == 0 || ir.EventType != MOUSE_EVENT
Karsten Hopp c7dbd3
  				|| !(pmer2->dwButtonState & LEFT_RIGHT))
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 1126,1132 ****
Karsten Hopp c7dbd3
  			{
Karsten Hopp c7dbd3
  			    if (pmer2->dwEventFlags != MOUSE_MOVED)
Karsten Hopp c7dbd3
  			    {
Karsten Hopp c7dbd3
! 				ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  				return decode_mouse_event(pmer2);
Karsten Hopp c7dbd3
  			    }
Karsten Hopp c7dbd3
--- 1195,1201 ----
Karsten Hopp c7dbd3
  			{
Karsten Hopp c7dbd3
  			    if (pmer2->dwEventFlags != MOUSE_MOVED)
Karsten Hopp c7dbd3
  			    {
Karsten Hopp c7dbd3
! 				read_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  				return decode_mouse_event(pmer2);
Karsten Hopp c7dbd3
  			    }
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 1134,1143 ****
Karsten Hopp c7dbd3
  				     s_yOldMouse == pmer2->dwMousePosition.Y)
Karsten Hopp c7dbd3
  			    {
Karsten Hopp c7dbd3
  				/* throw away spurious mouse move */
Karsten Hopp c7dbd3
! 				ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  				/* are there any more mouse events in queue? */
Karsten Hopp c7dbd3
! 				PeekConsoleInput(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  				if (cRecords==0 || ir.EventType != MOUSE_EVENT)
Karsten Hopp c7dbd3
  				    break;
Karsten Hopp c7dbd3
--- 1203,1212 ----
Karsten Hopp c7dbd3
  				     s_yOldMouse == pmer2->dwMousePosition.Y)
Karsten Hopp c7dbd3
  			    {
Karsten Hopp c7dbd3
  				/* throw away spurious mouse move */
Karsten Hopp c7dbd3
! 				read_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  				/* are there any more mouse events in queue? */
Karsten Hopp c7dbd3
! 				peek_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  				if (cRecords==0 || ir.EventType != MOUSE_EVENT)
Karsten Hopp c7dbd3
  				    break;
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 1374,1380 ****
Karsten Hopp c7dbd3
  	}
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  	cRecords = 0;
Karsten Hopp c7dbd3
! 	PeekConsoleInput(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  #ifdef FEAT_MBYTE_IME
Karsten Hopp c7dbd3
  	if (State & CMDLINE && msg_row == Rows - 1)
Karsten Hopp c7dbd3
--- 1443,1449 ----
Karsten Hopp c7dbd3
  	}
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  	cRecords = 0;
Karsten Hopp c7dbd3
! 	peek_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  #ifdef FEAT_MBYTE_IME
Karsten Hopp c7dbd3
  	if (State & CMDLINE && msg_row == Rows - 1)
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 1405,1411 ****
Karsten Hopp c7dbd3
  		if (ir.Event.KeyEvent.uChar.UnicodeChar == 0
Karsten Hopp c7dbd3
  			&& ir.Event.KeyEvent.wVirtualKeyCode == 13)
Karsten Hopp c7dbd3
  		{
Karsten Hopp c7dbd3
! 		    ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  		    continue;
Karsten Hopp c7dbd3
  		}
Karsten Hopp c7dbd3
  #endif
Karsten Hopp c7dbd3
--- 1474,1480 ----
Karsten Hopp c7dbd3
  		if (ir.Event.KeyEvent.uChar.UnicodeChar == 0
Karsten Hopp c7dbd3
  			&& ir.Event.KeyEvent.wVirtualKeyCode == 13)
Karsten Hopp c7dbd3
  		{
Karsten Hopp c7dbd3
! 		    read_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  		    continue;
Karsten Hopp c7dbd3
  		}
Karsten Hopp c7dbd3
  #endif
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 1414,1420 ****
Karsten Hopp c7dbd3
  		    return TRUE;
Karsten Hopp c7dbd3
  	    }
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
! 	    ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  	    if (ir.EventType == FOCUS_EVENT)
Karsten Hopp c7dbd3
  		handle_focus_event(ir);
Karsten Hopp c7dbd3
--- 1483,1489 ----
Karsten Hopp c7dbd3
  		    return TRUE;
Karsten Hopp c7dbd3
  	    }
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
! 	    read_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp c7dbd3
  
Karsten Hopp c7dbd3
  	    if (ir.EventType == FOCUS_EVENT)
Karsten Hopp c7dbd3
  		handle_focus_event(ir);
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 1484,1490 ****
Karsten Hopp c7dbd3
  	    return 0;
Karsten Hopp c7dbd3
  # endif
Karsten Hopp c7dbd3
  #endif
Karsten Hopp c7dbd3
! 	if (ReadConsoleInput(g_hConIn, &ir, 1, &cRecords) == 0)
Karsten Hopp c7dbd3
  	{
Karsten Hopp c7dbd3
  	    if (did_create_conin)
Karsten Hopp c7dbd3
  		read_error_exit();
Karsten Hopp c7dbd3
--- 1553,1559 ----
Karsten Hopp c7dbd3
  	    return 0;
Karsten Hopp c7dbd3
  # endif
Karsten Hopp c7dbd3
  #endif
Karsten Hopp c7dbd3
! 	if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0)
Karsten Hopp c7dbd3
  	{
Karsten Hopp c7dbd3
  	    if (did_create_conin)
Karsten Hopp c7dbd3
  		read_error_exit();
Karsten Hopp c7dbd3
*** ../vim-7.4.136/src/version.c	2014-01-10 13:05:12.000000000 +0100
Karsten Hopp c7dbd3
--- src/version.c	2014-01-10 13:42:34.000000000 +0100
Karsten Hopp c7dbd3
***************
Karsten Hopp c7dbd3
*** 740,741 ****
Karsten Hopp c7dbd3
--- 740,743 ----
Karsten Hopp c7dbd3
  {   /* Add new patch number below this line */
Karsten Hopp c7dbd3
+ /**/
Karsten Hopp c7dbd3
+     137,
Karsten Hopp c7dbd3
  /**/
Karsten Hopp c7dbd3
Karsten Hopp c7dbd3
-- 
Karsten Hopp c7dbd3
hundred-and-one symptoms of being an internet addict:
Karsten Hopp c7dbd3
131. You challenge authority and society by portnuking people
Karsten Hopp c7dbd3
Karsten Hopp c7dbd3
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp c7dbd3
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp c7dbd3
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp c7dbd3
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///