Skip to content

Commit 4fb7dde

Browse files
committed
Add One-Hand mice wheel scroll diff and merge (WinMerge#2435) (10)
1 parent 2ef7198 commit 4fb7dde

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

Src/DirView.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "SyntaxColors.h"
5050
#include "Shell.h"
5151
#include "DirTravel.h"
52+
#include "MouseHook.h"
5253
#include <numeric>
5354
#include <functional>
5455

@@ -638,6 +639,8 @@ void CDirView::Redisplay()
638639
*/
639640
void CDirView::OnContextMenu(CWnd*, CPoint point)
640641
{
642+
if (CMouseHook::IsRightWheelScrolling())
643+
return;
641644
if (GetListCtrl().GetItemCount() == 0)
642645
return;
643646
// Make sure window is active

Src/MergeEditView.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "Shell.h"
3434
#include "SelectPluginDlg.h"
3535
#include "Constants.h"
36+
#include "MouseHook.h"
3637

3738
#ifdef _DEBUG
3839
#define new DEBUG_NEW
@@ -2868,6 +2869,9 @@ void CMergeEditView::OnUpdateEditReplace(CCmdUI* pCmdUI)
28682869
*/
28692870
void CMergeEditView::OnContextMenu(CWnd* pWnd, CPoint point)
28702871
{
2872+
if (CMouseHook::IsRightWheelScrolling())
2873+
return;
2874+
28712875
CRect rect;
28722876
GetClientRect(rect);
28732877
ClientToScreen(rect);

Src/MouseHook.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <StdAfx.h>
22
#include "MouseHook.h"
3+
#include <chrono>
34

45
#ifndef WM_MOUSEHWHEEL
56
# define WM_MOUSEHWHEEL 0x20e
@@ -12,7 +13,7 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
1213

1314
if (wParam == WM_LBUTTONDOWN)
1415
{
15-
m_bIgnoreRBUp = false;
16+
EndRightWheelScrolling();
1617
}
1718
else if (wParam == WM_RBUTTONDOWN)
1819
{
@@ -21,11 +22,7 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
2122
else if (wParam == WM_RBUTTONUP)
2223
{
2324
m_bRButtonDown = false;
24-
if (m_bIgnoreRBUp)
25-
{
26-
m_bIgnoreRBUp = false;
27-
return 1;
28-
}
25+
EndRightWheelScrolling();
2926
}
3027
else if (wParam == WM_MOUSEWHEEL)
3128
{
@@ -92,14 +89,14 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
9289
if (zDelta > 0)
9390
{
9491
// RButton+ScrollUp as Alt+Up
95-
m_bIgnoreRBUp = true;
92+
StartRightWheelScrolling();
9693
PostMessage(hwndTarget, WM_COMMAND, ID_PREVDIFF, 0);
9794
return 1;
9895
}
9996
else if (zDelta < 0)
10097
{
10198
// RButton+ScrollDown as Alt+Down
102-
m_bIgnoreRBUp = true;
99+
StartRightWheelScrolling();
103100
PostMessage(hwndTarget, WM_COMMAND, ID_NEXTDIFF, 0);
104101
return 1;
105102
}
@@ -154,14 +151,14 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
154151
if (zDelta > 0)
155152
{
156153
// RButton+ScrollRight as Alt+Right
157-
m_bIgnoreRBUp = true;
154+
StartRightWheelScrolling();
158155
PostMessage(hwndTarget, WM_COMMAND, ID_L2R, 0);
159156
return 1;
160157
}
161158
else if (zDelta < 0)
162159
{
163160
// RButton+ScrollLeft as Alt+Left
164-
m_bIgnoreRBUp = true;
161+
StartRightWheelScrolling();
165162
PostMessage(hwndTarget, WM_COMMAND, ID_R2L, 0);
166163
return 1;
167164
}

Src/MouseHook.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ class CMouseHook
33
public:
44
static void SetMouseHook();
55
static void UnhookMouseHook();
6-
static bool IsRightWheelScrolling() { return m_bIgnoreRBUp; }
6+
static bool IsRightWheelScrolling() { return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - m_endTimeRightWheelScrolling).count() < 100; }
77
private:
88
static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
9+
inline static void StartRightWheelScrolling() { m_bIgnoreRBUp = true; }
10+
inline static void EndRightWheelScrolling() { if (!m_bIgnoreRBUp) return; m_endTimeRightWheelScrolling = std::chrono::system_clock::now(); m_bIgnoreRBUp = false; }
911
inline static HHOOK m_hMouseHook;
1012
inline static bool m_bIgnoreRBUp;
1113
inline static bool m_bRButtonDown;
14+
inline static std::chrono::system_clock::time_point m_endTimeRightWheelScrolling;
1215
};

0 commit comments

Comments
 (0)