don't send shift key to window (#21983)

This commit is contained in:
Davide Giacometti
2022-11-12 16:35:51 +01:00
committed by GitHub
parent a8d2aeedf2
commit 1aa04bc201
2 changed files with 36 additions and 6 deletions

View File

@@ -53,7 +53,8 @@ namespace WindowMoveHandlerUtils
WindowMoveHandler::WindowMoveHandler(const std::function<void()>& keyUpdateCallback) :
m_mouseState(false),
m_mouseHook(std::bind(&WindowMoveHandler::OnMouseDown, this)),
m_shiftKeyState(keyUpdateCallback),
m_leftShiftKeyState(keyUpdateCallback),
m_rightShiftKeyState(keyUpdateCallback),
m_ctrlKeyState(keyUpdateCallback),
m_keyUpdateCallback(keyUpdateCallback)
{
@@ -88,7 +89,8 @@ void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const
m_mouseHook.enable();
}
m_shiftKeyState.enable();
m_leftShiftKeyState.enable();
m_rightShiftKeyState.enable();
m_ctrlKeyState.enable();
// This updates m_dragEnabled depending on if the shift key is being held down
@@ -214,8 +216,12 @@ void WindowMoveHandler::MoveSizeEnd(HWND window, const std::unordered_map<HMONIT
return;
}
bool leftShiftPressed = m_leftShiftKeyState.state();
bool rightShiftPressed = m_rightShiftKeyState.state();
m_mouseHook.disable();
m_shiftKeyState.disable();
m_leftShiftKeyState.disable();
m_rightShiftKeyState.disable();
m_ctrlKeyState.disable();
if (m_draggedWindowWorkArea)
@@ -235,6 +241,19 @@ void WindowMoveHandler::MoveSizeEnd(HWND window, const std::unordered_map<HMONIT
}
else
{
if (FancyZonesSettings::settings().shiftDrag)
{
if (leftShiftPressed)
{
SwallowKey(VK_LSHIFT);
}
if (rightShiftPressed)
{
SwallowKey(VK_RSHIFT);
}
}
workArea->MoveSizeEnd(m_draggedWindow);
}
}
@@ -360,11 +379,11 @@ void WindowMoveHandler::UpdateDragState() noexcept
{
if (FancyZonesSettings::settings().shiftDrag)
{
m_dragEnabled = (m_shiftKeyState.state() ^ m_mouseState);
m_dragEnabled = ((m_leftShiftKeyState.state() || m_rightShiftKeyState.state()) ^ m_mouseState);
}
else
{
m_dragEnabled = !(m_shiftKeyState.state() ^ m_mouseState);
m_dragEnabled = !((m_leftShiftKeyState.state() || m_rightShiftKeyState.state()) ^ m_mouseState);
}
}
@@ -410,3 +429,12 @@ void WindowMoveHandler::ResetWindowTransparency() noexcept
m_windowTransparencyProperties.draggedWindow = nullptr;
}
}
void WindowMoveHandler::SwallowKey(const WORD key) noexcept
{
INPUT inputKey[1] = {};
inputKey[0].type = INPUT_KEYBOARD;
inputKey[0].ki.wVk = key;
inputKey[0].ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, inputKey, sizeof(INPUT));
}

View File

@@ -65,6 +65,7 @@ private:
void SetWindowTransparency(HWND window) noexcept;
void ResetWindowTransparency() noexcept;
void SwallowKey(const WORD key) noexcept;
bool m_inDragging{}; // Whether or not a move/size operation is currently active
HWND m_draggedWindow{}; // The window that is being moved/sized
@@ -76,7 +77,8 @@ private:
std::atomic<bool> m_mouseState;
SecondaryMouseButtonsHook m_mouseHook;
KeyState<VK_LSHIFT, VK_RSHIFT> m_shiftKeyState;
KeyState<VK_LSHIFT> m_leftShiftKeyState;
KeyState<VK_RSHIFT> m_rightShiftKeyState;
KeyState<VK_LCONTROL, VK_RCONTROL> m_ctrlKeyState;
std::function<void()> m_keyUpdateCallback;
};