mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Better handling of keys held down when IDE takes focus
This commit is contained in:
parent
ec61583db8
commit
88711eae69
2 changed files with 51 additions and 10 deletions
|
@ -128,8 +128,6 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
|
||||||
wc.lpszMenuName = NULL;
|
wc.lpszMenuName = NULL;
|
||||||
RegisterClassW(&wc);
|
RegisterClassW(&wc);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int requestedX = x;
|
int requestedX = x;
|
||||||
int requestedY = y;
|
int requestedY = y;
|
||||||
|
|
||||||
|
@ -279,6 +277,9 @@ WinBFWindow::WinBFWindow(BFWindow* parent, const StringImpl& title, int x, int y
|
||||||
mAlphaMaskWidth = 0;
|
mAlphaMaskWidth = 0;
|
||||||
mAlphaMaskHeight = 0;
|
mAlphaMaskHeight = 0;
|
||||||
mNeedsStateReset = false;
|
mNeedsStateReset = false;
|
||||||
|
mAwaitKeyReleases = false;
|
||||||
|
mAwaitKeyEventTick = 0;
|
||||||
|
mFocusLostTick = ::GetTickCount();
|
||||||
|
|
||||||
if (windowFlags & BFWINDOW_DEST_ALPHA)
|
if (windowFlags & BFWINDOW_DEST_ALPHA)
|
||||||
{
|
{
|
||||||
|
@ -351,6 +352,8 @@ void WinBFWindow::SetTitle(const char* title)
|
||||||
|
|
||||||
void WinBFWindow::LostFocus(BFWindow* newFocus)
|
void WinBFWindow::LostFocus(BFWindow* newFocus)
|
||||||
{
|
{
|
||||||
|
///OutputDebugStrF("Lost focus\n");
|
||||||
|
mFocusLostTick = ::GetTickCount();
|
||||||
WinBFWindow* bfNewFocus = (WinBFWindow*)newFocus;
|
WinBFWindow* bfNewFocus = (WinBFWindow*)newFocus;
|
||||||
mSoftHasFocus = false;
|
mSoftHasFocus = false;
|
||||||
for (int i = 0; i < KEYCODE_MAX; i++)
|
for (int i = 0; i < KEYCODE_MAX; i++)
|
||||||
|
@ -373,6 +376,9 @@ void WinBFWindow::LostFocus(BFWindow* newFocus)
|
||||||
|
|
||||||
void WinBFWindow::SetForeground()
|
void WinBFWindow::SetForeground()
|
||||||
{
|
{
|
||||||
|
bool hadFocus = mHasFocus;
|
||||||
|
DWORD prevFocusLostTick = mFocusLostTick;
|
||||||
|
|
||||||
if (mFlags & BFWINDOW_FAKEFOCUS)
|
if (mFlags & BFWINDOW_FAKEFOCUS)
|
||||||
{
|
{
|
||||||
mHasFocus = true;
|
mHasFocus = true;
|
||||||
|
@ -382,8 +388,13 @@ void WinBFWindow::SetForeground()
|
||||||
|
|
||||||
::SetFocus(mHWnd);
|
::SetFocus(mHWnd);
|
||||||
::SetForegroundWindow(mHWnd);
|
::SetForegroundWindow(mHWnd);
|
||||||
|
if ((!hadFocus) && (::GetTickCount() - prevFocusLostTick >= 1000))
|
||||||
|
{
|
||||||
|
mAwaitKeyReleases = true;
|
||||||
|
mAwaitKeyEventTick = ::GetTickCount();
|
||||||
|
}
|
||||||
|
|
||||||
//OutputDebugStrF("SetForeground %p\n", mHWnd);
|
//OutputDebugStrF("SetForeground %p %d %d %d\n", mHWnd, hadFocus, ::GetTickCount() - prevFocusLostTick, mAwaitKeyReleases);
|
||||||
}
|
}
|
||||||
|
|
||||||
static POINT gLastScreenMouseCoords = { -1, -1 };
|
static POINT gLastScreenMouseCoords = { -1, -1 };
|
||||||
|
@ -407,6 +418,30 @@ void WinBFWindow::RehupMouseOver(bool isMouseOver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WinBFWindow::CheckKeyReleases(bool isKeyDown)
|
||||||
|
{
|
||||||
|
if (!mAwaitKeyReleases)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Time expired with no key presses
|
||||||
|
if ((mAwaitKeyEventTick != 0) && (::GetTickCount() - mAwaitKeyEventTick > 120))
|
||||||
|
{
|
||||||
|
mAwaitKeyReleases = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
mAwaitKeyEventTick = 0;
|
||||||
|
|
||||||
|
bool hasKeyDown = false;
|
||||||
|
uint8 keysDown[256] = { 0 };
|
||||||
|
::GetKeyboardState((PBYTE)&keysDown);
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
if (keysDown[i] & 0x80)
|
||||||
|
hasKeyDown = true;
|
||||||
|
if (!hasKeyDown)
|
||||||
|
mAwaitKeyReleases = false;
|
||||||
|
return !mAwaitKeyReleases;
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
WinBFApp* app = (WinBFApp*) gBFApp;
|
WinBFApp* app = (WinBFApp*) gBFApp;
|
||||||
|
@ -876,6 +911,7 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
|
|
||||||
//NOTE: This line broke Alt+Gr for braces and such. Determine why this was needed.
|
//NOTE: This line broke Alt+Gr for braces and such. Determine why this was needed.
|
||||||
//if ((!mIsKeyDown[VK_MENU]) && (!mIsKeyDown[VK_CONTROL]))
|
//if ((!mIsKeyDown[VK_MENU]) && (!mIsKeyDown[VK_CONTROL]))
|
||||||
|
if (CheckKeyReleases(true))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (lParam & 0x7FFF); i++)
|
for (int i = 0; i < (lParam & 0x7FFF); i++)
|
||||||
mKeyCharFunc(this, (WCHAR)wParam);
|
mKeyCharFunc(this, (WCHAR)wParam);
|
||||||
|
@ -921,7 +957,7 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
|
|
||||||
if (!mIsMenuKeyHandled)
|
if (!mIsMenuKeyHandled)
|
||||||
{
|
{
|
||||||
if (mKeyDownFunc(this, keyCode, (lParam & 0x7FFF) != 0))
|
if ((CheckKeyReleases(true)) && (mKeyDownFunc(this, keyCode, (lParam & 0x7FFF) != 0)))
|
||||||
{
|
{
|
||||||
mIsMenuKeyHandled = true;
|
mIsMenuKeyHandled = true;
|
||||||
doResult = true;
|
doResult = true;
|
||||||
|
@ -941,7 +977,8 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
(aMenu->mKeyCtrl == mIsKeyDown[VK_CONTROL]) &&
|
(aMenu->mKeyCtrl == mIsKeyDown[VK_CONTROL]) &&
|
||||||
(aMenu->mKeyAlt == mIsKeyDown[VK_MENU]))
|
(aMenu->mKeyAlt == mIsKeyDown[VK_MENU]))
|
||||||
{
|
{
|
||||||
doResult = true;
|
if (CheckKeyReleases(true))
|
||||||
|
doResult = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -965,6 +1002,7 @@ LRESULT WinBFWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
mKeyUpFunc(this, keyCode);
|
mKeyUpFunc(this, keyCode);
|
||||||
mIsKeyDown[keyCode] = false;
|
mIsKeyDown[keyCode] = false;
|
||||||
}
|
}
|
||||||
|
CheckKeyReleases(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_SYSCOMMAND:
|
case WM_SYSCOMMAND:
|
||||||
|
|
|
@ -50,7 +50,9 @@ public:
|
||||||
bool mMouseVisible;
|
bool mMouseVisible;
|
||||||
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;
|
||||||
|
DWORD mAwaitKeyEventTick;
|
||||||
|
DWORD mFocusLostTick;
|
||||||
bool mNeedsStateReset;
|
bool mNeedsStateReset;
|
||||||
bool mKeyLayoutHasAltGr;
|
bool mKeyLayoutHasAltGr;
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ public:
|
||||||
virtual LRESULT WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
virtual LRESULT WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||||
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);
|
||||||
|
|
||||||
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