Skip to content

Commit

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

Expand Down Expand Up @@ -639,8 +638,6 @@ 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: 0 additions & 4 deletions Src/MergeEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "Shell.h"
#include "SelectPluginDlg.h"
#include "Constants.h"
#include "MouseHook.h"

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

CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
Expand Down
20 changes: 8 additions & 12 deletions Src/MouseHook.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#include <StdAfx.h>
#include "MouseHook.h"

void CALLBACK CMouseHook::TimerProc(HWND unnamedParam1, UINT unnamedParam2, UINT_PTR id, DWORD unnamedParam4HWND)
{
KillTimer(nullptr, id);
EndMenu();
m_bIgnoreRBUp = false;
}

LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(m_hMouseHook, nCode, wParam, lParam);

if (wParam == WM_RBUTTONDOWN)
if (wParam == WM_LBUTTONDOWN)
{
m_bIgnoreRBUp = false;
}
else if (wParam == WM_RBUTTONDOWN)
{
m_bRButtonDown = true;
}
Expand All @@ -22,9 +19,8 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
m_bRButtonDown = false;
if (m_bIgnoreRBUp)
{
LRESULT result = CallNextHookEx(m_hMouseHook, nCode, wParam, lParam);
SetTimer(nullptr, 0, USER_TIMER_MINIMUM, TimerProc);
return result;
m_bIgnoreRBUp = false;
return 1;
}
}
else if (wParam == WM_MOUSEWHEEL)
Expand Down Expand Up @@ -172,7 +168,7 @@ LRESULT CALLBACK CMouseHook::MouseProc(int nCode, WPARAM wParam, LPARAM lParam)

void CMouseHook::SetMouseHook()
{
m_hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, GetModuleHandle(nullptr), GetCurrentThreadId());
m_hMouseHook = SetWindowsHookEx(WH_MOUSE, MouseProc, AfxGetInstanceHandle(), GetCurrentThreadId());
}

void CMouseHook::UnhookMouseHook()
Expand Down
1 change: 0 additions & 1 deletion Src/MouseHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class CMouseHook
static bool IsRightWheelScrolling() { return m_bIgnoreRBUp; }
private:
static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
static void CALLBACK TimerProc(HWND unnamedParam1, UINT unnamedParam2, UINT_PTR id, DWORD unnamedParam4HWND);
inline static HHOOK m_hMouseHook;
inline static bool m_bIgnoreRBUp;
inline static bool m_bRButtonDown;
Expand Down

3 comments on commit a8befca

@lededev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tried to prevent the message from being passed on in WM_RBUTTONUP. It seems to work fine in MergeEditView, but it causes the side effect of multiple selections in DirView. The most reliable way is to add a check condition in OnContextMenu.

@lededev
Copy link
Contributor

@lededev lededev commented on a8befca Oct 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to avoid side effects is to prevent the message from being passed on in WM_RBUTTONDOWN and WM_RBUTTONUP message events at the same time. If there is no scroll wheel combination operation when the right button is released, Post a WM_CONTEXTMENU message to pop up the right-click menu.
But without WM_RBUTTONDOWN,this feature will lost:
MergeEditView.cpp

/**
 * @brief Called when mouse right button is pressed.
 *
 * If right button is pressed outside diffs, current diff
 * is deselected.
 */
void CMergeEditView::OnRButtonDown(UINT nFlags, CPoint point)
{
	CCrystalEditViewEx::OnRButtonDown(nFlags, point);
	DeselectDiffIfCursorNotInCurrentDiff();
}

Maybe Post WM_RBUTTONDOWN then WM_RBUTTONUP instead of WM_CONTEXTMENU can resolve this, but be careful of message processing dead loop.

@sdottaka
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! For now, I'll give up on preventing the context menu from appearing for the Image compare window, Binary compare window, and Webpage compare window.

Please sign in to comment.