提交 b4070921 编写于 作者: C Carlos Alberto Cortez

[fix] #639939: Manually and properly convert the bytes returned by XLookupString.

	* X11Keyboard.cs: Manually handle the conversion of the string
	returned by XLookupString, just as we were already doing for XIM
	support - using StringBuilder directly was somehow returning a
	corrupt buffer from time to time.
	Fixes #639939.
上级 43f7e0c4
......@@ -51,7 +51,7 @@ namespace System.Windows.Forms {
private XIMProperties ximStyle;
private EventMask xic_event_mask = EventMask.NoEventMask;
private StringBuilder lookup_buffer;
private byte [] utf8_buffer;
private byte [] lookup_byte_buffer = new byte [100];
private int min_keycode, max_keycode, keysyms_per_keycode, syms;
private int [] keyc2vkey = new int [256];
private int [] keyc2scan = new int [256];
......@@ -130,8 +130,6 @@ namespace System.Windows.Forms {
xim = XOpenIM (display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
if (xim == IntPtr.Zero)
Console.Error.WriteLine ("Could not get XIM");
else
utf8_buffer = new byte [100];
initialized = true;
}
......@@ -1181,19 +1179,26 @@ namespace System.Windows.Forms {
IntPtr xic = GetXic (client_window);
if (xic != IntPtr.Zero) {
do {
res = Xutf8LookupString (xic, ref xevent, utf8_buffer, 100, out keysym_res, out status);
res = Xutf8LookupString (xic, ref xevent, lookup_byte_buffer, 100, out keysym_res, out status);
if ((int) status != -1) // XLookupBufferOverflow
break;
utf8_buffer = new byte [utf8_buffer.Length << 1];
lookup_byte_buffer = new byte [lookup_byte_buffer.Length << 1];
} while (true);
lookup_buffer.Length = 0;
string s = Encoding.UTF8.GetString (utf8_buffer, 0, res);
string s = Encoding.UTF8.GetString (lookup_byte_buffer, 0, res);
lookup_buffer.Append (s);
keysym = (XKeySym) keysym_res.ToInt32 ();
return s.Length;
} else {
do {
res = XLookupString (ref xevent, lookup_byte_buffer, 100, out keysym_res, out status);
if ((int) status != -1) // XLookupBufferOverflow
break;
lookup_byte_buffer = new byte [lookup_byte_buffer.Length << 1];
} while (true);
lookup_buffer.Length = 0;
res = XLookupString (ref xevent, lookup_buffer, len, out keysym_res, IntPtr.Zero);
string s = Encoding.ASCII.GetString (lookup_byte_buffer, 0, res);
lookup_buffer.Append (s);
keysym = (XKeySym) keysym_res.ToInt32 ();
return res;
}
......@@ -1259,7 +1264,7 @@ namespace System.Windows.Forms {
private static extern bool XSetLocaleModifiers (string mods);
[DllImport ("libX11")]
internal extern static int XLookupString(ref XEvent xevent, StringBuilder buffer, int num_bytes, out IntPtr keysym, IntPtr status);
internal extern static int XLookupString(ref XEvent xevent, byte [] buffer, int num_bytes, out IntPtr keysym, out IntPtr status);
[DllImport ("libX11")]
internal extern static int Xutf8LookupString(IntPtr xic, ref XEvent xevent, byte [] buffer, int num_bytes, out IntPtr keysym, out IntPtr status);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册