From 567e3156f8dbf862a7697bcb60ea706622ccf3ab Mon Sep 17 00:00:00 2001 From: fanlumaster <1730976608@qq.com> Date: Fri, 31 Oct 2025 07:14:34 +0800 Subject: [PATCH] [feat]: IME tray icon right click menu --- src/IPC/Ipc.cpp | 22 ++++++++++++++++++++++ src/IPC/Ipc.h | 3 +++ src/Key/KeyHandler.cpp | 2 ++ src/LanguageBar/LanguageBar.cpp | 27 ++++++++++++++++++++------- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/IPC/Ipc.cpp b/src/IPC/Ipc.cpp index 199b07d0..0c43c8e7 100644 --- a/src/IPC/Ipc.cpp +++ b/src/IPC/Ipc.cpp @@ -398,6 +398,15 @@ int SendMoveCandidateWndEventToUIProcess() return 0; } +int SendLangbarRightClickEventToUIProcess(const RECT *prcArea) +{ + if (!canUseSharedMemory) + { + return SendLangbarRightClickEventToUIProcessViaNamedPipe(prcArea); + } + return 0; +} + // // Named pipe // @@ -716,5 +725,18 @@ int SendMoveCandidateWndEventToUIProcessViaNamedPipe() namedpipeData.event_type = 3; SendToNamedpipe(); + return 0; +} + +int SendLangbarRightClickEventToUIProcessViaNamedPipe(const RECT *prcArea) +{ + namedpipeData.event_type = 4; + /* 利用其他的字段,把图标的坐标传递过去 */ + namedpipeData.point[0] = prcArea->left; + namedpipeData.point[1] = prcArea->top; + namedpipeData.keycode = prcArea->right; + namedpipeData.modifiers_down = prcArea->bottom; + SendToNamedpipe(); + return 0; } \ No newline at end of file diff --git a/src/IPC/Ipc.h b/src/IPC/Ipc.h index 02e195ba..7c3d9b85 100644 --- a/src/IPC/Ipc.h +++ b/src/IPC/Ipc.h @@ -47,6 +47,7 @@ struct FanyImeSharedMemoryData // 1: FanyHideCandidateWndEvent // 2: FanyShowCandidateWndEvent // 3: FanyMoveCandidateWndEvent +// 4: FanyLangbarRightClickEvent // struct FanyImeNamedpipeData { @@ -93,6 +94,7 @@ int SendKeyEventToUIProcess(); int SendHideCandidateWndEventToUIProcess(); int SendShowCandidateWndEventToUIProcess(); int SendMoveCandidateWndEventToUIProcess(); +int SendLangbarRightClickEventToUIProcess(const RECT *prcArea); // // For named pipe @@ -110,6 +112,7 @@ int SendKeyEventToUIProcessViaNamedPipe(); int SendHideCandidateWndEventToUIProcessViaNamedPipe(); int SendShowCandidateWndEventToUIProcessViaNamedPipe(); int SendMoveCandidateWndEventToUIProcessViaNamedPipe(); +int SendLangbarRightClickEventToUIProcessViaNamedPipe(const RECT *prcArea); void ClearNamedpipeDataIfExists(); struct FanyImeNamedpipeDataToTsf *TryReadDataFromServerPipeWithTimeout(); struct FanyImeNamedpipeDataToTsf *ReadDataFromServerViaNamedPipe(); diff --git a/src/Key/KeyHandler.cpp b/src/Key/KeyHandler.cpp index 12f89407..cb13fbe6 100644 --- a/src/Key/KeyHandler.cpp +++ b/src/Key/KeyHandler.cpp @@ -233,6 +233,8 @@ HRESULT CMetasequoiaIME::_HandleCompositionInputWorker(_In_ CCompositionProcesso readingStr = GlobalIme::word_for_creating_word + readingStr; } } + /* 如果想要设置 tsf preedit 为空,可以在这里设置 */ + // readingStr = L""; curReadingStr.Set(readingStr.c_str(), readingStr.length()); if (GlobalSettings::getTsfPreeditStyle() == GlobalSettings::TsfPreeditStyle::Pinyin) diff --git a/src/LanguageBar/LanguageBar.cpp b/src/LanguageBar/LanguageBar.cpp index d7d5840a..e223e673 100644 --- a/src/LanguageBar/LanguageBar.cpp +++ b/src/LanguageBar/LanguageBar.cpp @@ -12,6 +12,8 @@ #include "LanguageBar.h" #include "Globals.h" #include "Compartment.h" +#include "Ipc.h" +#include "fmt/xchar.h" //+--------------------------------------------------------------------------- // @@ -105,7 +107,7 @@ CLangBarItemButton::CLangBarItemButton(REFGUID guidLangBar, LPCWSTR description, // initialize TF_LANGBARITEMINFO structure. _tfLangBarItemInfo.clsidService = Global::MetasequoiaIMECLSID; // This LangBarItem belongs to this TextService. - _tfLangBarItemInfo.guidItem = guidLangBar; // GUID of this LangBarItem. + _tfLangBarItemInfo.guidItem = guidLangBar; // GUID of this LangBarItem. _tfLangBarItemInfo.dwStyle = (TF_LBI_STYLE_BTN_BUTTON | TF_LBI_STYLE_SHOWNINTRAY); // This LangBar is a button type. _tfLangBarItemInfo.ulSort = 0; // The position of this LangBar Item is not specified. StringCchCopy(_tfLangBarItemInfo.szDescription, ARRAYSIZE(_tfLangBarItemInfo.szDescription), @@ -370,14 +372,25 @@ STDAPI CLangBarItemButton::GetTooltipString(_Out_ BSTR *pbstrToolTip) STDAPI CLangBarItemButton::OnClick(TfLBIClick click, POINT pt, _In_ const RECT *prcArea) { - click; - pt; - prcArea; + if (click == TF_LBI_CLK_RIGHT) + { +#ifdef FANY_DEBUG + OutputDebugString( + fmt::format(L"\nprcArea: ({}, {}, {}, {})\n", prcArea->left, prcArea->top, prcArea->right, prcArea->bottom) + .c_str()); + OutputDebugString(L"right click of lang bar item\n"); +#endif + SendLangbarRightClickEventToUIProcess(prcArea); + return S_OK; + } - BOOL isOn = FALSE; + if (click == TF_LBI_CLK_LEFT && _pCompartment) + { + BOOL isOn = FALSE; - _pCompartment->_GetCompartmentBOOL(isOn); - _pCompartment->_SetCompartmentBOOL(isOn ? FALSE : TRUE); + _pCompartment->_GetCompartmentBOOL(isOn); + _pCompartment->_SetCompartmentBOOL(isOn ? FALSE : TRUE); + } return S_OK; }