Skip to content

Commit

Permalink
Simplified "merge" to left and middle mouse buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
lededev authored and z committed Dec 20, 2024
1 parent 62eb1e5 commit 0aead50
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 73 deletions.
8 changes: 4 additions & 4 deletions Src/Merge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -4574,10 +4574,10 @@ STRINGTABLE
BEGIN
ID_MICE_PREVDIFF "\nPrevious Difference (Alt+Up)\n(Right Button+Wheel Up)\n(Alt+Wheel Up)"
ID_MICE_NEXTDIFF "\nNext Difference (Alt+Down)\n(Right Button+Wheel Down)\n(Alt+Wheel Down)"
ID_MICE_L2R "\nCopy to Right (Alt+Right)\n(Right Button+Wheel Right)\n(Alt+Wheel Right)\n(Right Button+Shift+Wheel Down)\n(Alt+Shift+Wheel Down)\n(Hold Right Button+Middle Button Click+Wheel Down)"
ID_MICE_R2L "\nCopy to Left (Alt+Left)\n(Right Button+Wheel Left)\n(Alt+Wheel Left)\n(Right Button+Shift+Wheel Up)\n(Alt+Shift+Wheel Up)\n(Hold Right Button+Middle Button Click+Wheel Up)"
ID_MICE_L2RNEXT "\nCopy to Right and Advance (Ctrl+Alt+Right)\n(Ctrl+Alt+Wheel Right)\n(Ctrl+Alt+Shift+Wheel Down)"
ID_MICE_R2LNEXT "\nCopy to Left and Advance (Ctrl+Alt+Left)\n(Ctrl+Alt+Wheel Left)\n(Ctrl+Alt+Shift+Wheel Up)"
ID_MICE_L2R "\nCopy to Right (Alt+Right)\n(Right Button+Middle Button)\n(Right Button+Wheel Right)\n(Alt+Wheel Right)\n(Right Button+Shift+Wheel Down)\n(Alt+Shift+Wheel Down)"
ID_MICE_R2L "\nCopy to Left (Alt+Left)\n(Right Button+Left Button)\n(Right Button+Wheel Left)\n(Alt+Wheel Left)\n(Right Button+Shift+Wheel Up)\n(Alt+Shift+Wheel Up)"
ID_MICE_L2RNEXT "\nCopy to Right and Advance (Ctrl+Alt+Right)\n(Ctrl+Right Button+Middle Button)\n(Ctrl+Alt+Wheel Right)\n(Ctrl+Alt+Shift+Wheel Down)"
ID_MICE_R2LNEXT "\nCopy to Left and Advance (Ctrl+Alt+Left)\n(Ctrl+Right Button+Left Button)\n(Ctrl+Alt+Wheel Left)\n(Ctrl+Alt+Shift+Wheel Up)"
END

STRINGTABLE
Expand Down
108 changes: 68 additions & 40 deletions Src/MouseHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,50 @@
#endif

// Define state matrix
const std::function<bool(LPARAM)> CMouseHook::stateMatrix[3][6] = {
const std::function<bool(LPARAM)> CMouseHook::stateMatrix[2][8] = {
// State::Idle
{
[](LPARAM) { Transition(State::RightButtonDown); return false; }, // WM_RBUTTONDOWN
[](LPARAM) { EndRightWheelScrolling(); return false; }, // WM_RBUTTONUP
[](LPARAM) { return false; }, // WM_LBUTTONDOWN
[](LPARAM) { return false; }, // WM_MBUTTONUP
[](LPARAM lParam) { return MouseWheelAction(lParam); }, // WM_MOUSEWHEEL
[](LPARAM lParam) { return MouseHWheelAction(lParam); } // WM_MOUSEHWHEEL
[](LPARAM) { // WM_RBUTTONDOWN
Transition(State::RightButtonDown);
return false;
},
[](LPARAM) { // WM_RBUTTONUP
EndRightWheelScrolling();
return false;
},
[](LPARAM) { return false; }, // WM_LBUTTONDOWN
[](LPARAM) { return false; }, // WM_LBUTTONUP
[](LPARAM) { return false; }, // WM_MBUTTONDOWN
[](LPARAM) { return false; }, // WM_MBUTTONUP
CMouseHook::MouseWheelAction, // WM_MOUSEWHEEL
CMouseHook::MouseHWheelAction // WM_MOUSEHWHEEL
},
// State::RightButtonDown
{
[](LPARAM) { return false; }, // WM_RBUTTONDOWN
[](LPARAM) { Transition(State::Idle); EndRightWheelScrolling(); return false; }, // WM_RBUTTONUP
[](LPARAM) { Transition(State::Idle); EndRightWheelScrolling(); return false; }, // WM_LBUTTONDOWN
[](LPARAM) { Transition(State::HorizontalScrollSimulated); return false; }, // WM_MBUTTONUP
[](LPARAM lParam) { return RightButtonDown_MouseWheel(lParam); }, // WM_MOUSEWHEEL
[](LPARAM lParam) { return RightButtonDown_MouseHWheel(lParam); } // WM_MOUSEHWHEEL
},
// State::HorizontalScrollSimulated
{
[](LPARAM) { return false; }, // WM_RBUTTONDOWN
[](LPARAM) { Transition(State::Idle); EndRightWheelScrolling(); return false; }, // WM_RBUTTONUP
[](LPARAM) { Transition(State::Idle); EndRightWheelScrolling(); return false; }, // WM_LBUTTONDOWN
[](LPARAM) { Transition(State::RightButtonDown); return false; }, // WM_MBUTTONUP
[](LPARAM lParam) { // WM_MOUSEWHEEL
const auto b = RightButtonDown_MouseWheel(lParam);
Transition(State::RightButtonDown);
return b;
[](LPARAM) { return false; }, // WM_RBUTTONDOWN
[](LPARAM) { // WM_RBUTTONUP
// Release Right button
Transition(State::Idle);
EndRightWheelScrolling();
return false;
},
[](LPARAM lParam) { // WM_MOUSEHWHEEL
const auto b = RightButtonDown_MouseHWheel(lParam);
Transition(State::RightButtonDown);
return b;
}
[](LPARAM) { // WM_LBUTTONDOWN
return CMouseHook::RightButtonDown_ButtonClick(true);
},
[](LPARAM) { // WM_LBUTTONUP
return m_bLeftBtnDown ? (m_bLeftBtnDown = false), true : false;
},
[](LPARAM) { // WM_MBUTTONDOWN
return CMouseHook::RightButtonDown_ButtonClick(false);
},
[](LPARAM) { // WM_MBUTTONUP
return m_bMidBtnDown ? (m_bMidBtnDown = false), true : false;
},
CMouseHook::RightButtonDown_MouseWheel, // WM_MOUSEWHEEL
CMouseHook::RightButtonDown_MouseHWheel // WM_MOUSEHWHEEL
}
};

void CMouseHook::Transition(State nextState) {
m_currentState = nextState;
}

LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
Expand All @@ -59,9 +61,11 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{WM_RBUTTONDOWN, 0}
,{WM_RBUTTONUP, 1}
,{WM_LBUTTONDOWN, 2}
,{WM_MBUTTONUP, 3}
,{WM_MOUSEWHEEL, 4}
,{WM_MOUSEHWHEEL, 5}
,{WM_LBUTTONUP , 3}
,{WM_MBUTTONDOWN, 4}
,{WM_MBUTTONUP , 5}
,{WM_MOUSEWHEEL, 6}
,{WM_MOUSEHWHEEL, 7}
};
auto it = actionIdx.find(static_cast<UINT>(wParam));
if (it != actionIdx.end())
Expand Down Expand Up @@ -101,8 +105,9 @@ bool CMouseHook::MouseWheelAction(LPARAM lParam)
PostMessage(hwndTarget, WM_COMMAND, ID_R2L, 0);
return true;
}
else if (m_currentState == State::Idle)
else
{
assert(m_currentState == State::Idle);
// Alt+ScrollUp as Alt+Up
PostMessage(hwndTarget, WM_COMMAND, ID_PREVDIFF, 0);
return true;
Expand All @@ -123,8 +128,9 @@ bool CMouseHook::MouseWheelAction(LPARAM lParam)
PostMessage(hwndTarget, WM_COMMAND, ID_L2R, 0);
return true;
}
else if (m_currentState == State::Idle)
else
{
assert(m_currentState == State::Idle);
// Alt+ScrollDown as Alt+Down
PostMessage(hwndTarget, WM_COMMAND, ID_NEXTDIFF, 0);
return true;
Expand Down Expand Up @@ -152,8 +158,9 @@ bool CMouseHook::MouseHWheelAction(LPARAM lParam)
PostMessage(hwndTarget, WM_COMMAND, ID_L2RNEXT, 0);
return true;
}
else if (m_currentState == State::Idle)
else
{
assert(m_currentState == State::Idle);
// Alt+HScrollRight as Alt+Right
PostMessage(hwndTarget, WM_COMMAND, ID_L2R, 0);
return true;
Expand All @@ -167,8 +174,9 @@ bool CMouseHook::MouseHWheelAction(LPARAM lParam)
PostMessage(hwndTarget, WM_COMMAND, ID_R2LNEXT, 0);
return true;
}
else if (m_currentState == State::Idle)
else
{
assert(m_currentState == State::Idle);
// Alt+HScrollLeft as Alt+Left
PostMessage(hwndTarget, WM_COMMAND, ID_R2L, 0);
return true;
Expand Down Expand Up @@ -237,3 +245,23 @@ void CMouseHook::UnhookMouseHook()
m_hMouseHook = nullptr;
}
}

bool CMouseHook::RightButtonDown_ButtonClick(bool isLeftButton)
{
const auto bControlDown = GetAsyncKeyState(VK_CONTROL) & 0x8000;
if(isLeftButton)
{
// Hold Right button + Left button click as Alt+Left, plus hold Ctrl as Ctrl+Alt+Left
m_bLeftBtnDown = true;
StartRightWheelScrolling();
PostMessage(GetForegroundWindow(), WM_COMMAND, bControlDown ? ID_R2LNEXT : ID_R2L, 0);
}
else
{
// Hold Right button + Middle button click as Alt+Right, plus hold Ctrl as Ctrl+Alt+Right
m_bMidBtnDown = true;
StartRightWheelScrolling();
PostMessage(GetForegroundWindow(), WM_COMMAND, bControlDown ? ID_L2RNEXT : ID_L2R, 0);
}
return true;
}
9 changes: 6 additions & 3 deletions Src/MouseHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ class CMouseHook
RightButtonDown,
HorizontalScrollSimulated
};
inline static State m_currentState;
static void Transition(State nextState);
inline static State m_currentState = State::Idle;
inline static void Transition(State nextState) { m_currentState = nextState; };
// State matrix definition
static const std::function<bool(LPARAM)> stateMatrix[3][6];
static const std::function<bool(LPARAM)> stateMatrix[2][8];

static bool MouseWheelAction(LPARAM lParam);
static bool MouseHWheelAction(LPARAM lParam);
static bool RightButtonDown_MouseWheel(LPARAM lParam);
static bool RightButtonDown_MouseHWheel(LPARAM lParam);
static bool RightButtonDown_ButtonClick(bool isLeftButton);
inline static bool m_bLeftBtnDown = false;
inline static bool m_bMidBtnDown = false;
};
27 changes: 11 additions & 16 deletions Translations/WinMerge/ChineseSimplified.po
Original file line number Diff line number Diff line change
Expand Up @@ -4391,45 +4391,40 @@ msgstr ""
"(鼠标右键+滚轮下滚)\n"
"(Alt+滚轮下滚)"

msgid "\nCopy to Right (Alt+Right)\n(Right Button+Wheel Right)\n(Alt+Wheel Right)\n(Right Button+Shift+Wheel Down)\n(Alt+Shift+Wheel Down)\n(Hold Right Button+Middle Button Click+Wheel Down)"
msgid "\nCopy to Right (Alt+Right)\n(Right Button+Middle Button)\n(Right Button+Wheel Right)\n(Alt+Wheel Right)\n(Right Button+Shift+Wheel Down)\n(Alt+Shift+Wheel Down)"
msgstr ""
"\n"
"复制到右侧 (Alt+Right)\n"
"(鼠标右键+鼠标中键)\n"
"(鼠标右键+滚轮右滚)\n"
"(Alt+滚轮右滚)\n"
"(Alt+Shift+滚轮下滚)"
"(鼠标右键+Shift+滚轮下滚)\n"
"(Alt+Shift+滚轮下滚)\n"
"(按住鼠标右键+点击鼠标中键+滚轮下滚)"

msgid "\nCopy to Left (Alt+Left)\n(Right Button+Wheel Left)\n(Alt+Wheel Left)\n(Right Button+Shift+Wheel Up)\n(Alt+Shift+Wheel Up)\n(Hold Right Button+Middle Button Click+Wheel Up)"
msgid "\nCopy to Left (Alt+Left)\n(Right Button+Left Button)\n(Right Button+Wheel Left)\n(Alt+Wheel Left)\n(Right Button+Shift+Wheel Up)\n(Alt+Shift+Wheel Up)"
msgstr ""
"\n"
"复制到左侧 (Alt+Left)\n"
"(鼠标右键+鼠标左键)\n"
"(鼠标右键+滚轮左滚)\n"
"(Alt+滚轮左滚)\n"
"(Alt+Shift+滚轮上滚)"
"(鼠标右键+Shift+滚轮上滚)\n"
"(Alt+Shift+滚轮上滚)\n"
"(按住鼠标右键+点击鼠标中键+滚轮上滚)"
"(Alt+Shift+滚轮上滚)"

msgid ""
"\n"
"Copy to Right and Advance (Ctrl+Alt+Right)\n"
"(Ctrl+Alt+Wheel Right)\n"
"(Ctrl+Alt+Shift+Wheel Down)"
msgid "\nCopy to Right and Advance (Ctrl+Alt+Right)\n(Ctrl+Right Button+Middle Button)\n(Ctrl+Alt+Wheel Right)\n(Ctrl+Alt+Shift+Wheel Down)"
msgstr ""
"\n"
"复制到右侧再到下一处差异 (Ctrl+Alt+Right)\n"
"(Ctrl+鼠标右键+鼠标中键)\n"
"(Ctrl+Alt+滚轮右滚)\n"
"(Ctrl+Alt+Shift+滚轮下滚)"

msgid ""
"\n"
"Copy to Left and Advance (Ctrl+Alt+Left)\n"
"(Ctrl+Alt+Wheel Left)\n"
"(Ctrl+Alt+Shift+Wheel Up)"
msgid "\nCopy to Left and Advance (Ctrl+Alt+Left)\n(Ctrl+Right Button+Left Button)\n(Ctrl+Alt+Wheel Left)\n(Ctrl+Alt+Shift+Wheel Up)"
msgstr ""
"\n"
"复制到左侧再到下一处差异 (Ctrl+Alt+Left)\n"
"(Ctrl+鼠标右键+鼠标左键)\n"
"(Ctrl+Alt+滚轮左滚)\n"
"(Ctrl+Alt+Shift+滚轮上滚)"

Expand Down
31 changes: 21 additions & 10 deletions Translations/WinMerge/ChineseTraditional.po
Original file line number Diff line number Diff line change
Expand Up @@ -5024,31 +5024,42 @@ msgstr "\n上一個差異 (Alt+Up)\n(滑鼠右鍵+滾輪上滾)\n(Alt+滾輪上
msgid "\nNext Difference (Alt+Down)\n(Right Button+Wheel Down)\n(Alt+Wheel Down)"
msgstr "\n下一個差異 (Alt+Down)\n(滑鼠右鍵+滾輪下滾)\n(Alt+滾輪下滾)"

msgid "\nCopy to Right (Alt+Right)\n(Right Button+Wheel Right)\n(Alt+Wheel Right)\n(Right Button+Shift+Wheel Down)\n(Alt+Shift+Wheel Down)\n(Hold Right Button+Middle Button Click+Wheel Down)"
msgid "\nCopy to Right (Alt+Right)\n(Right Button+Middle Button)\n(Right Button+Wheel Right)\n(Alt+Wheel Right)\n(Right Button+Shift+Wheel Down)\n(Alt+Shift+Wheel Down)"
msgstr ""
"\n"
"複製到右側 (Alt+Right)\n"
"(滑鼠右鍵+滑鼠中鍵)\n"
"(滑鼠右鍵+滾輪右滾)\n"
"(Alt+滾輪右滾)\n"
"(Alt+Shift+滾輪下滾)"
"(滑鼠右鍵+Shift+滾輪下滾)\n"
"(Alt+Shift+滾輪下滾)\n"
"(按住滑鼠右鍵+點擊滑鼠中鍵+滾輪下滾)"

msgid "\nCopy to Left (Alt+Left)\n(Right Button+Wheel Left)\n(Alt+Wheel Left)\n(Right Button+Shift+Wheel Up)\n(Alt+Shift+Wheel Up)\n(Hold Right Button+Middle Button Click+Wheel Up)"
msgid "\nCopy to Left (Alt+Left)\n(Right Button+Left Button)\n(Right Button+Wheel Left)\n(Alt+Wheel Left)\n(Right Button+Shift+Wheel Up)\n(Alt+Shift+Wheel Up)"
msgstr ""
"\n"
"複製到左側 (Alt+Left)\n"
"(滑鼠右鍵+滑鼠左鍵)\n"
"(滑鼠右鍵+滾輪左滾)\n"
"(Alt+滾輪左滾)\n"
"(Alt+Shift+滾輪上滾)"
"(滑鼠右鍵+Shift+滾輪上滾)\n"
"(Alt+Shift+滾輪上滾)\n"
"(按住滑鼠右鍵+點擊滑鼠中鍵+滾輪上滾)"
"(Alt+Shift+滾輪上滾)"

msgid "\nCopy to Right and Advance (Ctrl+Alt+Right)\n(Ctrl+Alt+Wheel Right)\n(Ctrl+Alt+Shift+Wheel Down)"
msgstr "\n複製到右側後到下一個 (Ctrl+Alt+Right)\n(Ctrl+Alt+滾輪右滾)\n(Ctrl+Alt+Shift+滾輪下滾)"
msgid "\nCopy to Right and Advance (Ctrl+Alt+Right)\n(Ctrl+Right Button+Middle Button)\n(Ctrl+Alt+Wheel Right)\n(Ctrl+Alt+Shift+Wheel Down)"
msgstr ""
"\n"
"複製到右側後到下一個 (Ctrl+Alt+Right)\n"
"(Ctrl+滑鼠右鍵+滑鼠中鍵)\n"
"(Ctrl+Alt+滾輪右滾)\n"
"(Ctrl+Alt+Shift+滾輪下滾)"

msgid "\nCopy to Left and Advance (Ctrl+Alt+Left)\n(Ctrl+Alt+Wheel Left)\n(Ctrl+Alt+Shift+Wheel Up)"
msgstr "\n複製到左側後到下一個 (Ctrl+Alt+Left)\n(Ctrl+Alt+滾輪左滾)\n(Ctrl+Alt+Shift+滾輪上滾)"
msgid "\nCopy to Left and Advance (Ctrl+Alt+Left)\n(Ctrl+Right Button+Left Button)\n(Ctrl+Alt+Wheel Left)\n(Ctrl+Alt+Shift+Wheel Up)"
msgstr ""
"\n"
"複製到左側後到下一個 (Ctrl+Alt+Left)\n"
"(Ctrl+滑鼠右鍵+滑鼠左鍵)\n"
"(Ctrl+Alt+滾輪左滾)\n"
"(Ctrl+Alt+Shift+滾輪上滾)"

msgid "Prettification"
msgstr "美化"
Expand Down

0 comments on commit 0aead50

Please sign in to comment.