mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
fix?
This commit is contained in:
parent
637ba78956
commit
e7815c59d5
1 changed files with 52 additions and 12 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
// #define IMEDEBUG
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
@ -108,6 +110,9 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
/// <summary>Undo range for modifying the buffer while composition is in progress.</summary>
|
/// <summary>Undo range for modifying the buffer while composition is in progress.</summary>
|
||||||
private (int Start, int End, int Cursor)? temporaryUndoSelection;
|
private (int Start, int End, int Cursor)? temporaryUndoSelection;
|
||||||
|
|
||||||
|
private bool updateInputLanguage = true;
|
||||||
|
private bool updateImeStatusAgain;
|
||||||
|
|
||||||
[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1003:Symbols should be spaced correctly", Justification = ".")]
|
[SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1003:Symbols should be spaced correctly", Justification = ".")]
|
||||||
static DalamudIme()
|
static DalamudIme()
|
||||||
{
|
{
|
||||||
|
|
@ -255,15 +260,24 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
private void WndProcHookManagerOnPreWndProc(WndProcEventArgs args)
|
private void WndProcHookManagerOnPreWndProc(WndProcEventArgs args)
|
||||||
{
|
{
|
||||||
if (!ImGuiHelpers.IsImGuiInitialized)
|
if (!ImGuiHelpers.IsImGuiInitialized)
|
||||||
|
{
|
||||||
|
this.updateInputLanguage = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Are we not the target of text input?
|
// Are we not the target of text input?
|
||||||
if (!ImGui.GetIO().WantTextInput)
|
if (!ImGui.GetIO().WantTextInput)
|
||||||
|
{
|
||||||
|
this.updateInputLanguage = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var hImc = ImmGetContext(args.Hwnd);
|
var hImc = ImmGetContext(args.Hwnd);
|
||||||
if (hImc == nint.Zero)
|
if (hImc == nint.Zero)
|
||||||
|
{
|
||||||
|
this.updateInputLanguage = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -313,16 +327,36 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (this.updateInputLanguage
|
||||||
|
|| (args.Message == WM.WM_IME_NOTIFY
|
||||||
|
&& (int)args.WParam
|
||||||
|
is IMN.IMN_SETCONVERSIONMODE
|
||||||
|
or IMN.IMN_OPENSTATUSWINDOW
|
||||||
|
or IMN.IMN_CLOSESTATUSWINDOW))
|
||||||
|
{
|
||||||
|
this.UpdateInputLanguage(hImc);
|
||||||
|
this.updateInputLanguage = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.updateImeStatusAgain)
|
||||||
|
{
|
||||||
|
this.ReplaceCompositionString(hImc, false);
|
||||||
|
this.UpdateCandidates(hImc);
|
||||||
|
this.updateImeStatusAgain = false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (args.Message)
|
switch (args.Message)
|
||||||
{
|
{
|
||||||
case WM.WM_IME_NOTIFY
|
case WM.WM_IME_NOTIFY
|
||||||
when (nint)args.WParam is IMN.IMN_OPENCANDIDATE or IMN.IMN_CLOSECANDIDATE
|
when (nint)args.WParam is IMN.IMN_OPENCANDIDATE or IMN.IMN_CLOSECANDIDATE
|
||||||
or IMN.IMN_CHANGECANDIDATE:
|
or IMN.IMN_CHANGECANDIDATE:
|
||||||
this.UpdateCandidates(hImc);
|
this.UpdateCandidates(hImc);
|
||||||
|
this.updateImeStatusAgain = true;
|
||||||
args.SuppressWithValue(0);
|
args.SuppressWithValue(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM.WM_IME_STARTCOMPOSITION:
|
case WM.WM_IME_STARTCOMPOSITION:
|
||||||
|
this.updateImeStatusAgain = true;
|
||||||
args.SuppressWithValue(0);
|
args.SuppressWithValue(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -330,17 +364,24 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
if (invalidTarget)
|
if (invalidTarget)
|
||||||
ImmNotifyIME(hImc, NI.NI_COMPOSITIONSTR, CPS_CANCEL, 0);
|
ImmNotifyIME(hImc, NI.NI_COMPOSITIONSTR, CPS_CANCEL, 0);
|
||||||
else
|
else
|
||||||
this.ReplaceCompositionString(hImc, (uint)args.LParam);
|
this.ReplaceCompositionString(hImc, ((int)args.LParam & GCS.GCS_RESULTSTR) != 0);
|
||||||
|
|
||||||
|
this.updateImeStatusAgain = true;
|
||||||
args.SuppressWithValue(0);
|
args.SuppressWithValue(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM.WM_IME_ENDCOMPOSITION:
|
case WM.WM_IME_ENDCOMPOSITION:
|
||||||
this.ClearState(hImc, false);
|
this.ClearState(hImc, false);
|
||||||
|
this.updateImeStatusAgain = true;
|
||||||
args.SuppressWithValue(0);
|
args.SuppressWithValue(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM.WM_IME_CHAR:
|
||||||
|
case WM.WM_IME_KEYDOWN:
|
||||||
|
case WM.WM_IME_KEYUP:
|
||||||
case WM.WM_IME_CONTROL:
|
case WM.WM_IME_CONTROL:
|
||||||
case WM.WM_IME_REQUEST:
|
case WM.WM_IME_REQUEST:
|
||||||
|
this.updateImeStatusAgain = true;
|
||||||
args.SuppressWithValue(0);
|
args.SuppressWithValue(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -348,9 +389,16 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
// Hide candidate and composition windows.
|
// Hide candidate and composition windows.
|
||||||
args.LParam = (LPARAM)((nint)args.LParam & ~(ISC_SHOWUICOMPOSITIONWINDOW | 0xF));
|
args.LParam = (LPARAM)((nint)args.LParam & ~(ISC_SHOWUICOMPOSITIONWINDOW | 0xF));
|
||||||
|
|
||||||
|
this.updateImeStatusAgain = true;
|
||||||
args.SuppressWithDefault();
|
args.SuppressWithDefault();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM.WM_IME_NOTIFY:
|
||||||
|
case WM.WM_IME_COMPOSITIONFULL:
|
||||||
|
case WM.WM_IME_SELECT:
|
||||||
|
this.updateImeStatusAgain = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case WM.WM_KEYDOWN when (int)args.WParam is
|
case WM.WM_KEYDOWN when (int)args.WParam is
|
||||||
VK.VK_TAB
|
VK.VK_TAB
|
||||||
or VK.VK_PRIOR
|
or VK.VK_PRIOR
|
||||||
|
|
@ -383,13 +431,6 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
ImmNotifyIME(hImc, NI.NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
|
ImmNotifyIME(hImc, NI.NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Message != WM.WM_MOUSEMOVE)
|
|
||||||
{
|
|
||||||
this.UpdateInputLanguage(hImc);
|
|
||||||
if (this.inputModeIcon == (char)SeIconChar.ImeKoreanHangul)
|
|
||||||
this.UpdateCandidates(hImc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
@ -446,9 +487,8 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReplaceCompositionString(HIMC hImc, uint comp)
|
private void ReplaceCompositionString(HIMC hImc, bool finalCommit)
|
||||||
{
|
{
|
||||||
var finalCommit = (comp & GCS.GCS_RESULTSTR) != 0;
|
|
||||||
var newString = finalCommit
|
var newString = finalCommit
|
||||||
? ImmGetCompositionString(hImc, GCS.GCS_RESULTSTR)
|
? ImmGetCompositionString(hImc, GCS.GCS_RESULTSTR)
|
||||||
: ImmGetCompositionString(hImc, GCS.GCS_COMPSTR);
|
: ImmGetCompositionString(hImc, GCS.GCS_COMPSTR);
|
||||||
|
|
@ -482,9 +522,9 @@ internal sealed unsafe class DalamudIme : IDisposable, IServiceType
|
||||||
this.compositionString = newString;
|
this.compositionString = newString;
|
||||||
this.compositionCursorOffset = ImmGetCompositionStringW(hImc, GCS.GCS_CURSORPOS, null, 0);
|
this.compositionCursorOffset = ImmGetCompositionStringW(hImc, GCS.GCS_CURSORPOS, null, 0);
|
||||||
|
|
||||||
if ((comp & GCS.GCS_COMPATTR) != 0)
|
var attrLength = ImmGetCompositionStringW(hImc, GCS.GCS_COMPATTR, null, 0);
|
||||||
|
if (attrLength > 0)
|
||||||
{
|
{
|
||||||
var attrLength = ImmGetCompositionStringW(hImc, GCS.GCS_COMPATTR, null, 0);
|
|
||||||
var attrPtr = stackalloc byte[attrLength];
|
var attrPtr = stackalloc byte[attrLength];
|
||||||
var attr = new Span<byte>(attrPtr, Math.Min(this.compositionString.Length, attrLength));
|
var attr = new Span<byte>(attrPtr, Math.Min(this.compositionString.Length, attrLength));
|
||||||
_ = ImmGetCompositionStringW(hImc, GCS.GCS_COMPATTR, attrPtr, (uint)attrLength);
|
_ = ImmGetCompositionStringW(hImc, GCS.GCS_COMPATTR, attrPtr, (uint)attrLength);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue