mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
don't send shift key to window (#21983)
This commit is contained in:
committed by
GitHub
parent
a8d2aeedf2
commit
1aa04bc201
@@ -53,7 +53,8 @@ namespace WindowMoveHandlerUtils
|
|||||||
WindowMoveHandler::WindowMoveHandler(const std::function<void()>& keyUpdateCallback) :
|
WindowMoveHandler::WindowMoveHandler(const std::function<void()>& keyUpdateCallback) :
|
||||||
m_mouseState(false),
|
m_mouseState(false),
|
||||||
m_mouseHook(std::bind(&WindowMoveHandler::OnMouseDown, this)),
|
m_mouseHook(std::bind(&WindowMoveHandler::OnMouseDown, this)),
|
||||||
m_shiftKeyState(keyUpdateCallback),
|
m_leftShiftKeyState(keyUpdateCallback),
|
||||||
|
m_rightShiftKeyState(keyUpdateCallback),
|
||||||
m_ctrlKeyState(keyUpdateCallback),
|
m_ctrlKeyState(keyUpdateCallback),
|
||||||
m_keyUpdateCallback(keyUpdateCallback)
|
m_keyUpdateCallback(keyUpdateCallback)
|
||||||
{
|
{
|
||||||
@@ -88,7 +89,8 @@ void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const
|
|||||||
m_mouseHook.enable();
|
m_mouseHook.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_shiftKeyState.enable();
|
m_leftShiftKeyState.enable();
|
||||||
|
m_rightShiftKeyState.enable();
|
||||||
m_ctrlKeyState.enable();
|
m_ctrlKeyState.enable();
|
||||||
|
|
||||||
// This updates m_dragEnabled depending on if the shift key is being held down
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool leftShiftPressed = m_leftShiftKeyState.state();
|
||||||
|
bool rightShiftPressed = m_rightShiftKeyState.state();
|
||||||
|
|
||||||
m_mouseHook.disable();
|
m_mouseHook.disable();
|
||||||
m_shiftKeyState.disable();
|
m_leftShiftKeyState.disable();
|
||||||
|
m_rightShiftKeyState.disable();
|
||||||
m_ctrlKeyState.disable();
|
m_ctrlKeyState.disable();
|
||||||
|
|
||||||
if (m_draggedWindowWorkArea)
|
if (m_draggedWindowWorkArea)
|
||||||
@@ -235,6 +241,19 @@ void WindowMoveHandler::MoveSizeEnd(HWND window, const std::unordered_map<HMONIT
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (FancyZonesSettings::settings().shiftDrag)
|
||||||
|
{
|
||||||
|
if (leftShiftPressed)
|
||||||
|
{
|
||||||
|
SwallowKey(VK_LSHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rightShiftPressed)
|
||||||
|
{
|
||||||
|
SwallowKey(VK_RSHIFT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
workArea->MoveSizeEnd(m_draggedWindow);
|
workArea->MoveSizeEnd(m_draggedWindow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -360,11 +379,11 @@ void WindowMoveHandler::UpdateDragState() noexcept
|
|||||||
{
|
{
|
||||||
if (FancyZonesSettings::settings().shiftDrag)
|
if (FancyZonesSettings::settings().shiftDrag)
|
||||||
{
|
{
|
||||||
m_dragEnabled = (m_shiftKeyState.state() ^ m_mouseState);
|
m_dragEnabled = ((m_leftShiftKeyState.state() || m_rightShiftKeyState.state()) ^ m_mouseState);
|
||||||
}
|
}
|
||||||
else
|
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;
|
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));
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ private:
|
|||||||
|
|
||||||
void SetWindowTransparency(HWND window) noexcept;
|
void SetWindowTransparency(HWND window) noexcept;
|
||||||
void ResetWindowTransparency() noexcept;
|
void ResetWindowTransparency() noexcept;
|
||||||
|
void SwallowKey(const WORD key) noexcept;
|
||||||
|
|
||||||
bool m_inDragging{}; // Whether or not a move/size operation is currently active
|
bool m_inDragging{}; // Whether or not a move/size operation is currently active
|
||||||
HWND m_draggedWindow{}; // The window that is being moved/sized
|
HWND m_draggedWindow{}; // The window that is being moved/sized
|
||||||
@@ -76,7 +77,8 @@ private:
|
|||||||
|
|
||||||
std::atomic<bool> m_mouseState;
|
std::atomic<bool> m_mouseState;
|
||||||
SecondaryMouseButtonsHook m_mouseHook;
|
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;
|
KeyState<VK_LCONTROL, VK_RCONTROL> m_ctrlKeyState;
|
||||||
std::function<void()> m_keyUpdateCallback;
|
std::function<void()> m_keyUpdateCallback;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user