mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 12:02:21 +02:00
New code for awaitKeyReleases
This commit is contained in:
parent
ec83ae50fa
commit
ca2301bfd3
2 changed files with 48 additions and 12 deletions
|
@ -278,7 +278,8 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
|
||||||
mAlphaMaskHeight = 0;
|
mAlphaMaskHeight = 0;
|
||||||
mNeedsStateReset = false;
|
mNeedsStateReset = false;
|
||||||
mAwaitKeyReleases = false;
|
mAwaitKeyReleases = false;
|
||||||
mAwaitKeyEventTick = 0;
|
mAwaitKeyReleasesEventTick = 0;
|
||||||
|
mAwaitKeyReleasesCheckIdx = 0;
|
||||||
mFocusLostTick = ::GetTickCount();
|
mFocusLostTick = ::GetTickCount();
|
||||||
|
|
||||||
if (windowFlags & BFWINDOW_DEST_ALPHA)
|
if (windowFlags & BFWINDOW_DEST_ALPHA)
|
||||||
|
@ -374,6 +375,20 @@ void WinBFWindow::LostFocus(BFWindow* newFocus)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WinBFWindow::GotFocus()
|
||||||
|
{
|
||||||
|
DWORD tickNow = ::GetTickCount();
|
||||||
|
|
||||||
|
//OutputDebugStrF("GotFocus since lost %d\n", tickNow - mFocusLostTick);
|
||||||
|
|
||||||
|
if (tickNow - mFocusLostTick >= 1000)
|
||||||
|
{
|
||||||
|
mAwaitKeyReleases = true;
|
||||||
|
mAwaitKeyReleasesCheckIdx = 0;
|
||||||
|
mAwaitKeyReleasesEventTick = ::GetTickCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WinBFWindow::SetForeground()
|
void WinBFWindow::SetForeground()
|
||||||
{
|
{
|
||||||
bool hadFocus = mHasFocus;
|
bool hadFocus = mHasFocus;
|
||||||
|
@ -388,11 +403,7 @@ void WinBFWindow::SetForeground()
|
||||||
|
|
||||||
::SetFocus(mHWnd);
|
::SetFocus(mHWnd);
|
||||||
::SetForegroundWindow(mHWnd);
|
::SetForegroundWindow(mHWnd);
|
||||||
if ((!hadFocus) && (::GetTickCount() - prevFocusLostTick >= 1000))
|
|
||||||
{
|
|
||||||
mAwaitKeyReleases = true;
|
|
||||||
mAwaitKeyEventTick = ::GetTickCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
//OutputDebugStrF("SetForeground %p %d %d %d\n", mHWnd, hadFocus, ::GetTickCount() - prevFocusLostTick, mAwaitKeyReleases);
|
//OutputDebugStrF("SetForeground %p %d %d %d\n", mHWnd, hadFocus, ::GetTickCount() - prevFocusLostTick, mAwaitKeyReleases);
|
||||||
}
|
}
|
||||||
|
@ -420,16 +431,20 @@ void WinBFWindow::RehupMouseOver(bool isMouseOver)
|
||||||
|
|
||||||
bool WinBFWindow::CheckKeyReleases(bool isKeyDown)
|
bool WinBFWindow::CheckKeyReleases(bool isKeyDown)
|
||||||
{
|
{
|
||||||
|
if (!mHasFocus)
|
||||||
|
GotFocus();
|
||||||
|
|
||||||
if (!mAwaitKeyReleases)
|
if (!mAwaitKeyReleases)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Time expired with no key presses
|
// Time expired with no key presses
|
||||||
if ((mAwaitKeyEventTick != 0) && (::GetTickCount() - mAwaitKeyEventTick > 120))
|
if ((mAwaitKeyReleasesEventTick != 0) && (mAwaitKeyReleasesCheckIdx == 0) && (::GetTickCount() - mAwaitKeyReleasesEventTick > 150))
|
||||||
{
|
{
|
||||||
|
//OutputDebugStrF("CheckKeyReleases no initial key press\n");
|
||||||
mAwaitKeyReleases = false;
|
mAwaitKeyReleases = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mAwaitKeyEventTick = 0;
|
mAwaitKeyReleasesCheckIdx++;
|
||||||
|
|
||||||
bool hasKeyDown = false;
|
bool hasKeyDown = false;
|
||||||
uint8 keysDown[256] = { 0 };
|
uint8 keysDown[256] = { 0 };
|
||||||
|
@ -437,8 +452,24 @@ bool WinBFWindow::CheckKeyReleases(bool isKeyDown)
|
||||||
for (int i = 0; i < 256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
if (keysDown[i] & 0x80)
|
if (keysDown[i] & 0x80)
|
||||||
hasKeyDown = true;
|
hasKeyDown = true;
|
||||||
|
|
||||||
|
if ((hasKeyDown) && (::GetTickCount() - mAwaitKeyReleasesEventTick >= 600))
|
||||||
|
{
|
||||||
|
String dbgStr = "CheckKeyReleases timeout. Keys down:";
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
if (keysDown[i] & 0x80)
|
||||||
|
dbgStr += StrFormat(" %2X", i);
|
||||||
|
dbgStr += "\n";
|
||||||
|
OutputDebugStr(dbgStr);
|
||||||
|
hasKeyDown = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasKeyDown)
|
if (!hasKeyDown)
|
||||||
|
{
|
||||||
mAwaitKeyReleases = false;
|
mAwaitKeyReleases = false;
|
||||||
|
mAwaitKeyReleasesCheckIdx = 0;
|
||||||
|
mAwaitKeyReleasesEventTick = 0;
|
||||||
|
}
|
||||||
return !mAwaitKeyReleases;
|
return !mAwaitKeyReleases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -877,6 +908,8 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
break;
|
break;
|
||||||
case WM_SETFOCUS:
|
case WM_SETFOCUS:
|
||||||
//OutputDebugStrF("WM_SETFOCUS %p\n", hWnd);
|
//OutputDebugStrF("WM_SETFOCUS %p\n", hWnd);
|
||||||
|
if (!mHasFocus)
|
||||||
|
GotFocus();
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
mSoftHasFocus = true;
|
mSoftHasFocus = true;
|
||||||
mGotFocusFunc(this);
|
mGotFocusFunc(this);
|
||||||
|
@ -1045,10 +1078,11 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
}
|
}
|
||||||
else if ((isFocused) && (!mHasFocus) && (checkNonFake == this))
|
else if ((isFocused) && (!mHasFocus) && (checkNonFake == this))
|
||||||
{
|
{
|
||||||
|
//OutputDebugStrF("Timer detected got focus %p\r\n", hWnd);
|
||||||
|
GotFocus();
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
mSoftHasFocus = true;
|
mSoftHasFocus = true;
|
||||||
mGotFocusFunc(this);
|
mGotFocusFunc(this);
|
||||||
//OutputDebugStrF("Timer detected got focus %p\r\n", hWnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mSoftHasFocus = mHasFocus;
|
mSoftHasFocus = mHasFocus;
|
||||||
|
|
|
@ -51,7 +51,8 @@ public:
|
||||||
bool mHasFocus;
|
bool mHasFocus;
|
||||||
bool mSoftHasFocus; // Mostly tracks mHasFocus except for when we get an explicit 'LostFocus' callback
|
bool mSoftHasFocus; // Mostly tracks mHasFocus except for when we get an explicit 'LostFocus' callback
|
||||||
bool mAwaitKeyReleases;
|
bool mAwaitKeyReleases;
|
||||||
DWORD mAwaitKeyEventTick;
|
int mAwaitKeyReleasesCheckIdx;
|
||||||
|
DWORD mAwaitKeyReleasesEventTick;
|
||||||
DWORD mFocusLostTick;
|
DWORD mFocusLostTick;
|
||||||
bool mNeedsStateReset;
|
bool mNeedsStateReset;
|
||||||
bool mKeyLayoutHasAltGr;
|
bool mKeyLayoutHasAltGr;
|
||||||
|
@ -61,6 +62,7 @@ public:
|
||||||
static LRESULT CALLBACK WindowProcStub(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK WindowProcStub(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||||
void RehupMouseOver(bool isMouseOver);
|
void RehupMouseOver(bool isMouseOver);
|
||||||
bool CheckKeyReleases(bool isKeyDown);
|
bool CheckKeyReleases(bool isKeyDown);
|
||||||
|
void GotFocus();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags);
|
WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y, int width, int height, int windowFlags);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue