Skip to content

Commit

Permalink
Add One-Hand mice wheel scroll diff and merge (#2435) (10)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Oct 13, 2024
1 parent 2ef7198 commit 4fb7dde
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Src/DirView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "SyntaxColors.h"
#include "Shell.h"
#include "DirTravel.h"
#include "MouseHook.h"
#include <numeric>
#include <functional>

Expand Down Expand Up @@ -638,6 +639,8 @@ void CDirView::Redisplay()
*/
void CDirView::OnContextMenu(CWnd*, CPoint point)
{
if (CMouseHook::IsRightWheelScrolling())
return;
if (GetListCtrl().GetItemCount() == 0)
return;
// Make sure window is active
Expand Down
4 changes: 4 additions & 0 deletions Src/MergeEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "Shell.h"
#include "SelectPluginDlg.h"
#include "Constants.h"
#include "MouseHook.h"

#ifdef _DEBUG
#define new DEBUG_NEW
Expand Down Expand Up @@ -2868,6 +2869,9 @@ void CMergeEditView::OnUpdateEditReplace(CCmdUI* pCmdUI)
*/
void CMergeEditView::OnContextMenu(CWnd* pWnd, CPoint point)
{
if (CMouseHook::IsRightWheelScrolling())
return;

CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
Expand Down
17 changes: 7 additions & 10 deletions Src/MouseHook.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <StdAfx.h>
#include "MouseHook.h"
#include <chrono>

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

if (wParam == WM_LBUTTONDOWN)
{
m_bIgnoreRBUp = false;
EndRightWheelScrolling();
}
else if (wParam == WM_RBUTTONDOWN)
{
Expand All @@ -21,11 +22,7 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
else if (wParam == WM_RBUTTONUP)
{
m_bRButtonDown = false;
if (m_bIgnoreRBUp)
{
m_bIgnoreRBUp = false;
return 1;
}
EndRightWheelScrolling();
}
else if (wParam == WM_MOUSEWHEEL)
{
Expand Down Expand Up @@ -92,14 +89,14 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
if (zDelta > 0)
{
// RButton+ScrollUp as Alt+Up
m_bIgnoreRBUp = true;
StartRightWheelScrolling();
PostMessage(hwndTarget, WM_COMMAND, ID_PREVDIFF, 0);
return 1;
}
else if (zDelta < 0)
{
// RButton+ScrollDown as Alt+Down
m_bIgnoreRBUp = true;
StartRightWheelScrolling();
PostMessage(hwndTarget, WM_COMMAND, ID_NEXTDIFF, 0);
return 1;
}
Expand Down Expand Up @@ -154,14 +151,14 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
if (zDelta > 0)
{
// RButton+ScrollRight as Alt+Right
m_bIgnoreRBUp = true;
StartRightWheelScrolling();
PostMessage(hwndTarget, WM_COMMAND, ID_L2R, 0);
return 1;
}
else if (zDelta < 0)
{
// RButton+ScrollLeft as Alt+Left
m_bIgnoreRBUp = true;
StartRightWheelScrolling();
PostMessage(hwndTarget, WM_COMMAND, ID_R2L, 0);
return 1;
}
Expand Down
5 changes: 4 additions & 1 deletion Src/MouseHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ class CMouseHook
public:
static void SetMouseHook();
static void UnhookMouseHook();
static bool IsRightWheelScrolling() { return m_bIgnoreRBUp; }
static bool IsRightWheelScrolling() { return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - m_endTimeRightWheelScrolling).count() < 100; }
private:
static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
inline static void StartRightWheelScrolling() { m_bIgnoreRBUp = true; }
inline static void EndRightWheelScrolling() { if (!m_bIgnoreRBUp) return; m_endTimeRightWheelScrolling = std::chrono::system_clock::now(); m_bIgnoreRBUp = false; }
inline static HHOOK m_hMouseHook;
inline static bool m_bIgnoreRBUp;
inline static bool m_bRButtonDown;
inline static std::chrono::system_clock::time_point m_endTimeRightWheelScrolling;
};

0 comments on commit 4fb7dde

Please sign in to comment.