Skip to content

Commit

Permalink
1、托盘菜单增加「快捷键开关」
Browse files Browse the repository at this point in the history
2、修复Python IDE中英文状态Shift+数字不能上屏
  • Loading branch information
Techince committed Nov 15, 2023
1 parent c2ade87 commit 814c089
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 89 deletions.
1 change: 0 additions & 1 deletion WeaselIPC/WeaselIPC.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@
<ClCompile Include="Committer.cpp" />
<ClCompile Include="ContextUpdater.cpp" />
<ClCompile Include="WeaselClientImpl.ixx" />
<ClCompile Include="WeaselSchemas.ixx" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
Expand Down
3 changes: 0 additions & 3 deletions WeaselIPC/WeaselIPC.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@
<ClCompile Include="Styler.ixx">
<Filter>Module Files\Deserializer</Filter>
</ClCompile>
<ClCompile Include="WeaselSchemas.ixx">
<Filter>Module Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
Expand Down
6 changes: 4 additions & 2 deletions WeaselIPC/WeaselSchemas.ixx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module;
#include <boost/serialization/vector.hpp>
#include <boost/serialization/string.hpp>
export module WeaselSchemas;
import <boost/serialization/vector.hpp>;
import <boost/serialization/string.hpp>;


export
{
Expand Down
46 changes: 40 additions & 6 deletions WeaselTSF/CompartmentTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,33 +235,67 @@ HRESULT WeaselTSF::_InitGlobalCompartment()

if (SUCCEEDED(ret))
{
ret = pDaemonCompartment->GetCompartment(WEASEL_COMPARTMENT_GLOAL_DEAMON, &_pGlobalCompartmentDaemon);
ret = pDaemonCompartment->GetCompartment(WEASEL_COMPARTMENT_GLOAL_DEAMON, &_pGlobalCompartment);

if (SUCCEEDED(ret))
{
VARIANT var{};
ret = _pGlobalCompartmentDaemon->GetValue(&var);
ret = _pGlobalCompartment->GetValue(&var);

if (SUCCEEDED(ret))
{
if (var.vt == VT_I4)
{
if ((var.lVal & 0xFF00) != 0xFC00)
{
var.lVal = 0xFC01;
ret = _pGlobalCompartmentDaemon->SetValue(_tfClientId, &var);
var.lVal = 0xFC03;
ret = _pGlobalCompartment->SetValue(_tfClientId, &var);
SetBit(WeaselFlag::DAEMON_ENABLE);
SetBit(WeaselFlag::PRESERVED_KEY_SWITCH);

}
else
{
byte value = var.bVal;
SetBit(WeaselFlag::DAEMON_ENABLE, static_cast<bool>(value & 0x1));
SetBit(WeaselFlag::PRESERVED_KEY_SWITCH, static_cast<bool>(value & 0x2));
}
}
else
{
var.vt = VT_I4;
var.lVal = 0xFC01;
ret = _pGlobalCompartmentDaemon->SetValue(_tfClientId, &var);
var.lVal = 0xFC03;
ret = _pGlobalCompartment->SetValue(_tfClientId, &var);
SetBit(WeaselFlag::DAEMON_ENABLE);
SetBit(WeaselFlag::PRESERVED_KEY_SWITCH);
}
}

}
}
return ret;
}

void WeaselTSF::UpdateGlobalCompartment(bool in)
{
VARIANT var{};

if (in)
{
var.vt = VT_I4;
byte v1 = GetBit(WeaselFlag::DAEMON_ENABLE) ? 1 : 0;
byte v2 = GetBit(WeaselFlag::PRESERVED_KEY_SWITCH) ? 2 : 0;
var.lVal = 0xFC00 | v1 | v2;

_pGlobalCompartment->SetValue(_tfClientId, &var);
}
else if (SUCCEEDED(_pGlobalCompartment->GetValue(&var)))
{
if (var.vt == VT_I4)
{
byte value = var.bVal;
SetBit(WeaselFlag::DAEMON_ENABLE, value & 0x1);
SetBit(WeaselFlag::PRESERVED_KEY_SWITCH, value & 0x2);
}
}
}
10 changes: 3 additions & 7 deletions WeaselTSF/Composition.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ STDAPI CStartCompositionEditSession::DoEditSession(TfEditCookie ec)
hr = _pContext->SetSelection(ec, 1, &tfSelection);
}
#ifdef TEST
LOG(INFO) << std::format("From CStartCompositionEditSession::DoEditSession. hr = {:#x}", (unsigned)hr);
LOG(INFO) << std::format("From CStartCompositionEditSession::DoEditSession. hr = 0x{:X}", (unsigned)hr);
#endif // TEST

return hr;
Expand All @@ -176,7 +176,7 @@ STDAPI CEndCompositionEditSession::DoEditSession(TfEditCookie ec)

auto hr = _pComposition->EndComposition(ec);
#ifdef TEST
LOG(INFO) << std::format("From CEndCompositionEditSession::DoEditSession. hr = {:#x}", (unsigned)hr);
LOG(INFO) << std::format("From CEndCompositionEditSession::DoEditSession. hr = 0x{:X}", (unsigned)hr);
#endif // TEST
_pTextService->_FinalizeComposition();
return hr;
Expand All @@ -189,11 +189,7 @@ STDAPI CGetTextExtentEditSession::DoEditSession(TfEditCookie ec)
BOOL fClipped;
HRESULT hr;

if (_pComposition != nullptr && SUCCEEDED(_pComposition->GetRange(&pRangeComposition)))
{

}
else
if (_pComposition == nullptr || FAILED(_pComposition->GetRange(&pRangeComposition)))
{
// composition end
// note: selection.range is always an empty range
Expand Down
6 changes: 3 additions & 3 deletions WeaselTSF/CompositionTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ STDAPI WeaselTSF::OnCompositionTerminated(TfEditCookie ecWrite, ITfComposition*
#endif // TEST
_AbortComposition();

if (GetBit(WeaselFlag::AUTOCAD))
if (GetBit(WeaselFlag::AUTOCAD)) // 无焦点输入时,AutoCAD会终止首码的合成
{
if (GetBit(WeaselFlag::RETRY_INPUT))
{
Expand All @@ -164,9 +164,9 @@ STDAPI WeaselTSF::OnCompositionTerminated(TfEditCookie ecWrite, ITfComposition*
}

}
else if (!GetBit(WeaselFlag::FOCUS_CHANGED))
else if (!GetBit(WeaselFlag::FOCUS_CHANGED)) // 排除失去焦点
{
if (GetBit(WeaselFlag::FIRST_KEY_COMPOSITION))
if (GetBit(WeaselFlag::FIRST_KEY_COMPOSITION)) // 重发意外终止的首码事件
{
SetBit(WeaselFlag::RETRY_COMPOSITION);
RetryKey();
Expand Down
14 changes: 7 additions & 7 deletions WeaselTSF/KeyEventSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import WeaselIPC;
import KeyEvent;
import CandidateList;

void WeaselTSF::_ProcessKeyEvent(WPARAM wParam, LPARAM lParam, BOOL* pfEaten)
void WeaselTSF::_ProcessKeyEvent(WPARAM wParam, LPARAM lParam, BOOL* pfEaten, bool isTest)
{
if (!_IsKeyboardOpen())
return;
Expand Down Expand Up @@ -52,7 +52,7 @@ void WeaselTSF::_ProcessKeyEvent(WPARAM wParam, LPARAM lParam, BOOL* pfEaten)
}
break;
}
if (!(*pfEaten) && !(lParam >> 31) && (isdigit(ke.keycode) || ispunct(ke.keycode)) && !(ke.mask & (ibus::CONTROL_MASK | ibus::ALT_MASK)))
if (!isTest && !(*pfEaten) && !(lParam >> 31) && (isdigit(ke.keycode) || ispunct(ke.keycode)) && !(ke.mask & (ibus::CONTROL_MASK | ibus::ALT_MASK)))
{
SetBit(WeaselFlag::EATEN);
_keycode = ke.keycode;
Expand Down Expand Up @@ -114,7 +114,7 @@ STDAPI WeaselTSF::OnTestKeyDown(ITfContext* pContext, WPARAM wParam, LPARAM lPar
return S_OK;
}
}
_ProcessKeyEvent(wParam, lParam, pfEaten);
_ProcessKeyEvent(wParam, lParam, pfEaten, true);
if (*pfEaten)
{
_fTestKeyDownPending = true;
Expand Down Expand Up @@ -146,7 +146,7 @@ STDAPI WeaselTSF::OnKeyDown(ITfContext* pContext, WPARAM wParam, LPARAM lParam,
LOG(INFO) << std::format("From OnKeyDown. *pfEaten = {}", *pfEaten);
#endif // TEST
}
if (lParam == 0x4000'0000)
if (lParam == 0x4000'0000 || lParam == 0x4000'0001)
{
SetBit(WeaselFlag::RETRY_INPUT);
OnCompositionTerminated(_dwTextEditSinkCookie, _pComposition);
Expand All @@ -173,7 +173,7 @@ STDAPI WeaselTSF::OnTestKeyUp(ITfContext* pContext, WPARAM wParam, LPARAM lParam
_UpdateComposition(pContext);
return S_OK;
}
_ProcessKeyEvent(wParam, lParam, pfEaten);
_ProcessKeyEvent(wParam, lParam, pfEaten, true);
_UpdateComposition(pContext);
if (*pfEaten)
{
Expand Down Expand Up @@ -221,7 +221,7 @@ STDAPI WeaselTSF::OnPreservedKey(ITfContext* pContext, REFGUID rguid, BOOL* pfEa
else if (IsEqualGUID(rguid, WEASEL_DAEMON_PRESERVED_KEY))
{
_bitset.flip(static_cast<int>(WeaselFlag::DAEMON_ENABLE));
if (_pGlobalCompartmentDaemon)
if (_pGlobalCompartment)
{
VARIANT var{};
var.vt = VT_I4;
Expand All @@ -233,7 +233,7 @@ STDAPI WeaselTSF::OnPreservedKey(ITfContext* pContext, REFGUID rguid, BOOL* pfEa
{
var.lVal = 0xFC00;
}
_pGlobalCompartmentDaemon->SetValue(_tfClientId, &var);
_pGlobalCompartment->SetValue(_tfClientId, &var);
}
}
return S_OK;
Expand Down
12 changes: 4 additions & 8 deletions WeaselTSF/LanguageBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,10 @@ void CLangBarItemButton::RightClick(POINT& pt)
CheckMenuItem(hSubMenu, ID_STYLE_CARET_FOLLOWING,
MF_BYCOMMAND | (_textService.GetBit(WeaselFlag::CARET_FOLLOWING) ? MF_CHECKED : MF_UNCHECKED));

VARIANT var{};
if (SUCCEEDED(_textService._GetGlobalCompartmentDaemon()->GetValue(&var)))
{
if (var.vt == VT_I4)
{
_textService.SetBit(WeaselFlag::DAEMON_ENABLE, var.bVal);
}
}
_textService.UpdateGlobalCompartment(false);
CheckMenuItem(hSubMenu, ID_STYLE_PRESERVED_KEY_SWITCH,
MF_BYCOMMAND | (_textService.GetBit(WeaselFlag::PRESERVED_KEY_SWITCH) ? MF_CHECKED : MF_UNCHECKED));

CheckMenuItem(popupMenu, ID_WEASELTRAY_DAEMON_ENABLE,
MF_BYCOMMAND | (_textService.GetBit(WeaselFlag::DAEMON_ENABLE) ? MF_CHECKED : MF_UNCHECKED));
UINT wID = TrackPopupMenuEx(popupMenu, TPM_CENTERALIGN | TPM_NONOTIFY | TPM_RETURNCMD | TPM_HORPOSANIMATION, pt.x, pt.y - 32, hwnd, NULL);
Expand Down
26 changes: 11 additions & 15 deletions WeaselTSF/LanguageBarTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,8 @@ void WeaselTSF::_HandleLangBarMenuSelect(UINT wID)

case ID_WEASELTRAY_DAEMON_ENABLE:
{
HRESULT hr;
if (_pGlobalCompartmentDaemon)
{
VARIANT var{};
var.vt = VT_I4;
if (GetBit(WeaselFlag::DAEMON_ENABLE))
{
var.lVal = 0xFC00;
}
else
{
var.lVal = 0xFC01;
}
hr = _pGlobalCompartmentDaemon->SetValue(_tfClientId, &var);
}
Flip(WeaselFlag::DAEMON_ENABLE);
UpdateGlobalCompartment();
#ifdef TEST
LOG(INFO) << std::format("From WeaselTSF::_HandleLangBarMenuSelect. hr = {:#x}", (size_t)hr);
#endif // TEST
Expand All @@ -91,6 +78,15 @@ void WeaselTSF::_HandleLangBarMenuSelect(UINT wID)
_cand->SetCaretFollowing(GetBit(WeaselFlag::CARET_FOLLOWING));
break;

case ID_STYLE_PRESERVED_KEY_SWITCH:
Flip(WeaselFlag::PRESERVED_KEY_SWITCH);
UpdateGlobalCompartment();
if (GetBit(WeaselFlag::PRESERVED_KEY_SWITCH))
_InitPreservedKey();
else
_UninitPreservedKey();
break;

DEFAULT:
default:
m_client.TrayCommand(wID);
Expand Down
12 changes: 10 additions & 2 deletions WeaselTSF/StatusSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ BOOL WeaselTSF::_InitStatusSink()

if (FAILED(_pThreadMgr->QueryInterface(&pSource)))
{
#ifdef TEST
LOG(INFO) << std::format("WeaselTSF::_InitStatusSink. First.");
#endif // TEST
return FALSE;
}

if (FAILED(pSource->AdviseSink(IID_ITfStatusSink, (ITfStatusSink*)this, &_dwStatusSinkCookie)))
E_INVALIDARG;
CONNECT_E_CANNOTCONNECT;
auto hr = pSource->AdviseSink(IID_ITfStatusSink, (ITfStatusSink*)this, &_dwStatusSinkCookie);
if (FAILED(hr))
{
#ifdef TEST
LOG(INFO) << std::format("WeaselTSF::_InitStatusSink. Second. hr = 0x{:X}", (unsigned)hr);
#endif // TEST
return FALSE;
}

Expand Down
4 changes: 2 additions & 2 deletions WeaselTSF/TextEditSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ STDAPI WeaselTSF::OnEndEdit(ITfContext* pContext, TfEditCookie ecReadOnly, ITfEd
STDAPI WeaselTSF::OnLayoutChange(ITfContext* pContext, TfLayoutCode lcode, ITfContextView* pContextView)
{
#ifdef TEST
LOG(INFO) << std::format("From WeaselTSF::OnLayoutChange. lcode = {:#x}", (unsigned)lcode);
LOG(INFO) << std::format("From WeaselTSF::OnLayoutChange. pContext = 0x{:X}, _pTextEditSinkContext = 0x{:X}", (size_t)pContext, (size_t)_pTextEditSinkContext.p);
#endif // TEST
if (!_IsComposing())
return S_OK;

if (pContext != _pTextEditSinkContext)
return S_OK;

if (GetBit(WeaselFlag::CARET_FOLLOWING) && lcode == TF_LC_CHANGE)
if (GetBit(WeaselFlag::CARET_FOLLOWING))
{
_UpdateCompositionWindow(pContext);
}
Expand Down
15 changes: 4 additions & 11 deletions WeaselTSF/WeaselTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@ STDAPI WeaselTSF::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClientId, DW
ResetBit(WeaselFlag::SUPPORT_DISPLAY_ATTRIBUTE);
}

if (!_InitPreservedKey())
goto ExitError;

if (!_InitLanguageBar())
goto ExitError;

Expand All @@ -236,6 +233,9 @@ STDAPI WeaselTSF::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClientId, DW
if (!_InitCompartment())
goto ExitError;

if (GetBit(WeaselFlag::PRESERVED_KEY_SWITCH))
_InitPreservedKey();

return S_OK;

ExitError:
Expand Down Expand Up @@ -277,14 +277,7 @@ void WeaselTSF::_EnsureServerConnected()
}
if (!m_client.Echo())
{
VARIANT var{};
if (SUCCEEDED(_GetGlobalCompartmentDaemon()->GetValue(&var)))
{
if (var.vt == VT_I4)
{
SetBit(WeaselFlag::DAEMON_ENABLE, var.bVal);
}
}
UpdateGlobalCompartment();
if (GetBit(WeaselFlag::DAEMON_ENABLE))
{
execute(std::format(LR"({}\WeaselServer.exe)", WeaselRootPath()));
Expand Down
Loading

0 comments on commit 814c089

Please sign in to comment.