Skip to content

Commit

Permalink
切换进程时,实时更新托盘图标
Browse files Browse the repository at this point in the history
  • Loading branch information
Techince committed Mar 3, 2024
1 parent f0c0391 commit 413cdf1
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
4 changes: 0 additions & 4 deletions WeaselSetup/InstallOptionsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class InstallOptionsDialog : public CDialogImpl<InstallOptionsDialog>
LRESULT OnUseCustomDir(WORD, WORD code, HWND, BOOL&);
LRESULT OnBrowser(WORD, WORD code, HWND, BOOL&);

void UpdateWidgets();
void Modify();
void ResetServer();

CButton cn_;
CButton tw_;
CButton remove_;
Expand Down
Binary file modified WeaselSetup/WeaselSetup.rc
Binary file not shown.
2 changes: 1 addition & 1 deletion WeaselSetup/imesetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int uninstall_ime_file(const std::wstring& ext, bool silent, ime_register_func f
GetSystemWow64Directory(path, _countof(path));
imePath = path;
imePath += L"\\weasel" + ext;
retval += func(imePath, false, true, false, silent);
retval += func(imePath, false, true, false, silent);

if (!delete_file(imePath))
{
Expand Down
6 changes: 6 additions & 0 deletions WeaselSetup/imesetup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

extern const GUID c_clsidTextService;

void enable_profile(BOOL fEnable, bool hant, const GUID& clsidTextServicee);
int register_text_service(const std::wstring& tsf_path, bool register_ime, bool is_wow64, bool hant, bool silent, const GUID& clsidTextService);
Binary file modified WeaselSetup/resource.h
Binary file not shown.
10 changes: 3 additions & 7 deletions WeaselTSF/LanguageBarTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module;
#include "Globals.h"
#include "ctffunc.h"
#include <format>
#include <thread>
#include <shellapi.h>
#include "resource.h"
module WeaselTSF;
Expand Down Expand Up @@ -55,8 +54,8 @@ void WeaselTSF::_HandleLangBarMenuSelect(UINT wID)
{
Flip(WeaselFlag::DAEMON_ENABLE);
UpdateGlobalCompartment();
}
break;
break;
}

case ID_STYLE_CARET_FOLLOWING:
_bitset.flip(static_cast<int>(WeaselFlag::CARET_FOLLOWING));
Expand All @@ -73,10 +72,7 @@ void WeaselTSF::_HandleLangBarMenuSelect(UINT wID)
break;

case ID_WEASELTRAY_RERUN_SERVICE:
{
std::wstring rootPath{ WeaselRootPath() };
ShellExecuteW(nullptr, L"open", std::format(LR"({}\start_service.bat)", rootPath).data(), NULL, rootPath.data(), SW_HIDE);
}
execute(std::format(LR"({}\WeaselServer.exe)", WeaselRootPath()));
break;

DEFAULT:
Expand Down
43 changes: 12 additions & 31 deletions WeaselTSF/ThreadFocusSink.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,31 @@
module;
#include "stdafx.h"
#include "test.h"
#ifdef TEST
#define WEASEL_ENABLE_LOGGING
#include "logging.h"
#endif // TEST
module WeaselTSF;
import CandidateList;
import ResponseParser;

STDMETHODIMP WeaselTSF::OnSetThreadFocus()
{
#ifdef TEST
LOG(INFO) << std::format("From WeaselTSF::OnSetThreadFocus. _pComposition ? {:s}", (bool)_IsComposing());
std::wstring buffer = std::format(L"From WeaselTSF::OnSetThreadFocus(). ascii_mode = {:s}\n", _status.ascii_mode);
WriteConsole(buffer);
#endif // TEST
if (_pComposition)
if (m_client.Echo())
{
com_ptr<ITfDocumentMgr> pCandidateListDocumentMgr;
if (SUCCEEDED(_pTextEditSinkContext->GetDocumentMgr(&pCandidateListDocumentMgr)))
{
if (pCandidateListDocumentMgr == _pDocMgrLastFocused)
{
_cand->SetThreadFocus();
}
}
m_client.ProcessKeyEvent(0);
_UpdateComposition(_pEditSessionContext);
}
#ifdef TEST
buffer = std::format(L"From WeaselTSF::OnSetThreadFocus(). ascii_mode = {:s}\n", _status.ascii_mode);
WriteConsole(buffer);
#endif // TEST

return S_OK;
}

STDMETHODIMP WeaselTSF::OnKillThreadFocus()
{
#ifdef TEST
LOG(INFO) << std::format("From WeaselTSF::OnKillThreadFocus. _pComposition ? {:s}", (bool)_IsComposing());
#endif // TEST
if (_pComposition)
{
com_ptr<ITfDocumentMgr> pCandidateListDocumentMgr;

if (SUCCEEDED(_pTextEditSinkContext->GetDocumentMgr(&pCandidateListDocumentMgr)))
{
if (_pDocMgrLastFocused)
{
_pDocMgrLastFocused.Release();
}
_pDocMgrLastFocused = pCandidateListDocumentMgr;
}
_cand->KillThreadFocus();
}
return S_OK;
}

Expand Down
7 changes: 7 additions & 0 deletions WeaselTSF/WeaselTSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ WeaselTSF::WeaselTSF()
_dwTextEditSinkCookie = TF_INVALID_COOKIE;
_dwTextLayoutSinkCookie = TF_INVALID_COOKIE;
_activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE;
_dwThreadFocusSinkCookie = TF_INVALID_COOKIE;

_cand.Attach(new CCandidateList(*this));
SetBit(WeaselFlag::SUPPORT_DISPLAY_ATTRIBUTE);
Expand Down Expand Up @@ -78,6 +79,8 @@ STDAPI WeaselTSF::QueryInterface(REFIID riid, void** ppvObject)
*ppvObject = (ITfDisplayAttributeProvider*)this;
else if (IsEqualIID(riid, IID_ITfCleanupContextDurationSink))
*ppvObject = (ITfCleanupContextDurationSink*)this;
else if (IsEqualIID(riid, IID_ITfThreadFocusSink))
*ppvObject = (ITfThreadFocusSink*)this;

if (*ppvObject)
{
Expand Down Expand Up @@ -127,6 +130,7 @@ STDAPI WeaselTSF::Deactivate()
_UninitLanguageBar();

_UninitCompartment();
_UninitThreadFocusSink();

_tfClientId = TF_CLIENTID_NULL;

Expand Down Expand Up @@ -212,6 +216,9 @@ STDAPI WeaselTSF::ActivateEx(ITfThreadMgr* pThreadMgr, TfClientId tfClientId, DW
if (!_InitLanguageBar())
SetBit(WeaselFlag::INIT_LANGUAGEBAR_FAILED);

if (!_InitThreadFocusSink())
goto ExitError;

#ifdef TEST
buffer = std::format(L"From WeaselActivateEx(). IsKeyboardOpen\n");
WriteConsole(buffer);
Expand Down
12 changes: 11 additions & 1 deletion WeaselTSF/WeaselTSF.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export
public ITfActiveLanguageProfileNotifySink,
public ITfEditSession,
public ITfDisplayAttributeProvider,
public ITfCleanupContextDurationSink
public ITfCleanupContextDurationSink,
public ITfThreadFocusSink
{
public:
WeaselTSF();
Expand Down Expand Up @@ -77,6 +78,10 @@ export
STDMETHODIMP EnumDisplayAttributeInfo(__RPC__deref_out_opt IEnumTfDisplayAttributeInfo** ppEnum);
STDMETHODIMP GetDisplayAttributeInfo(__RPC__in REFGUID guidInfo, __RPC__deref_out_opt ITfDisplayAttributeInfo** ppInfo);

/* ITfThreadFocusSink */
STDMETHODIMP OnSetThreadFocus();
STDMETHODIMP OnKillThreadFocus();

/* ITfCompartmentEventSink */
// STDMETHODIMP OnChange(_In_ REFGUID guid);

Expand Down Expand Up @@ -185,6 +190,9 @@ export
void _ShowLanguageBar(BOOL show);
void _EnableLanguageBar(BOOL enable);

BOOL _InitThreadFocusSink();
void _UninitThreadFocusSink();

BOOL _InsertText(ITfContext* pContext, std::wstring_view text);

void _DeleteCandidateList();
Expand Down Expand Up @@ -250,6 +258,8 @@ export
// The cookie of ActiveLanguageProfileNotifySink
DWORD _activeLanguageProfileNotifySinkCookie;

DWORD _dwThreadFocusSinkCookie;

RECT m_rcFallback{};
HWND m_hwnd{};
std::bitset<32> _bitset{};
Expand Down
1 change: 1 addition & 0 deletions WeaselTSF/WeaselTSF.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TextEditSink.cpp" />
<ClCompile Include="ThreadFocusSink.cpp" />
<ClCompile Include="ThreadMgrEventSink.cpp" />
<ClCompile Include="WeaselFlag.ixx" />
<ClCompile Include="WeaselTSF.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions WeaselTSF/WeaselTSF.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<ClCompile Include="CleanupContextDurationSink.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ThreadFocusSink.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
Expand Down

0 comments on commit 413cdf1

Please sign in to comment.