Skip to content

Commit

Permalink
Mouse LeftUp event on video area is now delayed in anticipation of a …
Browse files Browse the repository at this point in the history
…possible double-click. If a double-click occurs, then both LeftUp events are skipped. This prevents two unwanted (un)pause actions when toggling fullscreen with a double-click.

The delay is equal to the maximum double-click time configured in Windows, which on most systems is set to approximately 500 milliseconds. If that value is larger than 900ms, then no delay is applied (old behavior).
  • Loading branch information
clsid2 committed Nov 27, 2022
1 parent eab8d92 commit 93fe4dc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
54 changes: 52 additions & 2 deletions src/mpc-hc/MouseTouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ CMouse::CMouse(CMainFrame* pMainFrm, bool bD3DFS/* = false*/)
: m_bD3DFS(bD3DFS)
, m_pMainFrame(pMainFrm)
, m_dwMouseHiderStartTick(0)
, m_bLeftDown(false)
, m_bLeftUpDelayed(false)
, m_bLeftUpIgnoreNext(false)
, m_bLeftDoubleStarted(false)
, m_leftDoubleStartTime(0)
, m_popupMenuUninitTime(0)
Expand Down Expand Up @@ -120,6 +123,11 @@ void CMouse::ResetToBlankState()
m_drag = Drag::NO_DRAG;
m_cursor = Cursor::ARROW;
m_switchingToFullscreen.first = false;
m_bLeftUpIgnoreNext = false;
if (m_bLeftUpDelayed) {
m_bLeftUpDelayed = false;
KillTimer(GetWnd(), (UINT_PTR)this);
}
}

void CMouse::StartMouseHider(const CPoint& screenPoint)
Expand Down Expand Up @@ -274,6 +282,7 @@ void CMouse::InternalOnLButtonDown(UINT nFlags, const CPoint& point)
m_bLeftDown = false;
GetWnd().SetFocus();
SetCursor(nFlags, point);

if (MVRDown(nFlags, point)) {
return;
}
Expand All @@ -293,6 +302,8 @@ void CMouse::InternalOnLButtonDown(UINT nFlags, const CPoint& point)
return;
}

ASSERT(!m_bLeftUpIgnoreNext);

m_bLeftDown = true;
bool bDouble = false;
if (m_bLeftDoubleStarted &&
Expand All @@ -306,6 +317,17 @@ void CMouse::InternalOnLButtonDown(UINT nFlags, const CPoint& point)
m_leftDoubleStartTime = GetMessageTime();
m_leftDoubleStartPoint = point;
}

if (m_bLeftUpDelayed) {
KillTimer(GetWnd(), (UINT_PTR)this);
if (bDouble) {
m_bLeftUpDelayed = false;
m_bLeftUpIgnoreNext = true;
} else {
PerformDelayedLeftUp();
}
}

auto onButton = [&]() {
GetWnd().SetCapture();
bool ret = false;
Expand All @@ -328,15 +350,43 @@ void CMouse::InternalOnLButtonDown(UINT nFlags, const CPoint& point)
GetWnd().ClientToScreen(&m_beginDragPoint);
}
}

void CMouse::PerformDelayedLeftUp()
{
m_bLeftUpDelayed = false;
bool bIsOnFS = IsOnFullscreenWindow();
OnButton(wmcmd::LUP, m_LeftUpPoint, bIsOnFS);
m_LeftUpPoint = CPoint();
}

void CMouse::OnTimerLeftUp(HWND hWnd, UINT nMsg, UINT_PTR nIDEvent, DWORD dwTime)
{
CMouse* pCMouse = (CMouse*)nIDEvent;
if (pCMouse && pCMouse->m_bLeftUpDelayed) {
KillTimer(hWnd, nIDEvent);
pCMouse->PerformDelayedLeftUp();
}
}

void CMouse::InternalOnLButtonUp(UINT nFlags, const CPoint& point)
{
ReleaseCapture();
if (!MVRUp(nFlags, point)) {
if (!MVRUp(nFlags, point) && !m_bLeftUpIgnoreNext) {
bool bIsOnFS = IsOnFullscreenWindow();
if (!(m_bD3DFS && bIsOnFS && m_pMainFrame->m_OSD.OnLButtonUp(nFlags, point)) && m_bLeftDown) {
OnButton(wmcmd::LUP, point, bIsOnFS);
UINT dctime = GetDoubleClickTime();
if (dctime <= 900u && m_pMainFrame->GetLoadState() == MLS::LOADED) {
ASSERT(!m_bLeftUpDelayed);
m_bLeftUpDelayed = true;
m_LeftUpPoint = point;
SetTimer(GetWnd(), (UINT_PTR)this, dctime, OnTimerLeftUp);
} else {
OnButton(wmcmd::LUP, point, bIsOnFS);
}
}
}
m_bLeftUpIgnoreNext = false;

m_drag = Drag::NO_DRAG;
m_bLeftDown = false;
SetCursor(nFlags, point);
Expand Down
6 changes: 6 additions & 0 deletions src/mpc-hc/MouseTouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class CMouse
CPoint m_beginDragPoint;
CPoint m_hideCursorPoint;
bool m_bLeftDown;
bool m_bLeftUpDelayed;
bool m_bLeftUpIgnoreNext;
CPoint m_LeftUpPoint;
bool m_bLeftDoubleStarted;
CPoint m_leftDoubleStartPoint;
int m_leftDoubleStartTime;
Expand Down Expand Up @@ -104,6 +107,9 @@ class CMouse
bool MVRDown(UINT nFlags, const CPoint& point);
bool MVRUp(UINT nFlags, const CPoint& point);

void PerformDelayedLeftUp();
static void CALLBACK OnTimerLeftUp(HWND hWnd, UINT nMsg, UINT_PTR nIDEvent, DWORD dwTime);

protected:
void InternalOnLButtonDown(UINT nFlags, const CPoint& point);
void InternalOnLButtonUp(UINT nFlags, const CPoint& point);
Expand Down

0 comments on commit 93fe4dc

Please sign in to comment.