mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[FancyZones] Use Ctrl+Win+Alt+arrows to Expand/shrink windows to adjacent zones (#6446)
* Added an Alt key hook * Refactor a block of code into a method * Again refactored existing code * Apparently Win+Alt does not reach FancyZones * Using Ctrl+alt instead of Win+alt for now * It works * Fixed VD change * Remove unused member * Fix compilation error * Enable shrinking * Fixed comments in .h files * Remove newline * Refactored a function into two The next task is to simplify their code. * Updated a comment * Update a variable name * Reverted to the old implementation of directional move * More refactoring * Remove space * Fixed windows getting stuck * Changed function name
This commit is contained in:
@@ -207,6 +207,7 @@ private:
|
||||
bool OnSnapHotkeyBasedOnZoneNumber(HWND window, DWORD vkCode) noexcept;
|
||||
bool OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept;
|
||||
bool OnSnapHotkey(DWORD vkCode) noexcept;
|
||||
bool ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr<IZoneWindow> zoneWindow) noexcept;
|
||||
|
||||
void RegisterVirtualDesktopUpdates(std::vector<GUID>& ids) noexcept;
|
||||
|
||||
@@ -524,21 +525,23 @@ FancyZones::OnKeyDown(PKBDLLHOOKSTRUCT info) noexcept
|
||||
// Return true to swallow the keyboard event
|
||||
bool const shift = GetAsyncKeyState(VK_SHIFT) & 0x8000;
|
||||
bool const win = GetAsyncKeyState(VK_LWIN) & 0x8000 || GetAsyncKeyState(VK_RWIN) & 0x8000;
|
||||
if (win && !shift)
|
||||
bool const alt = GetAsyncKeyState(VK_MENU) & 0x8000;
|
||||
bool const ctrl = GetAsyncKeyState(VK_CONTROL) & 0x8000;
|
||||
if ((win && !shift && !ctrl) || (win && ctrl && alt))
|
||||
{
|
||||
bool const ctrl = GetAsyncKeyState(VK_CONTROL) & 0x8000;
|
||||
if (ctrl)
|
||||
{
|
||||
// Temporarily disable Win+Ctrl+Number functionality
|
||||
//if ((info->vkCode >= '0') && (info->vkCode <= '9'))
|
||||
//{
|
||||
// // Win+Ctrl+Number will cycle through ZoneSets
|
||||
// Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /*inMoveSize*/);
|
||||
// CycleActiveZoneSet(info->vkCode);
|
||||
// return true;
|
||||
//}
|
||||
}
|
||||
else if ((info->vkCode == VK_RIGHT) || (info->vkCode == VK_LEFT) || (info->vkCode == VK_UP) || (info->vkCode == VK_DOWN))
|
||||
// Temporarily disable Win+Ctrl+Number functionality
|
||||
// if (ctrl)
|
||||
// {
|
||||
// if ((info->vkCode >= '0') && (info->vkCode <= '9'))
|
||||
// {
|
||||
// // Win+Ctrl+Number will cycle through ZoneSets
|
||||
// Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /*inMoveSize*/);
|
||||
// CycleActiveZoneSet(info->vkCode);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
if ((info->vkCode == VK_RIGHT) || (info->vkCode == VK_LEFT) || (info->vkCode == VK_UP) || (info->vkCode == VK_DOWN))
|
||||
{
|
||||
if (ShouldProcessSnapHotkey(info->vkCode))
|
||||
{
|
||||
@@ -1142,7 +1145,7 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept
|
||||
{
|
||||
// Multi monitor environment.
|
||||
// First, try to stay on the same monitor
|
||||
bool success = m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndPosition(window, vkCode, false, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current));
|
||||
bool success = ProcessDirectedSnapHotkey(window, vkCode, false, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current));
|
||||
if (success)
|
||||
{
|
||||
return true;
|
||||
@@ -1250,7 +1253,7 @@ bool FancyZones::OnSnapHotkeyBasedOnPosition(HWND window, DWORD vkCode) noexcept
|
||||
else
|
||||
{
|
||||
// Single monitor environment, or combined multi-monitor environment.
|
||||
return m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndPosition(window, vkCode, true, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current));
|
||||
return ProcessDirectedSnapHotkey(window, vkCode, true, m_workAreaHandler.GetWorkArea(m_currentDesktopId, current));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1271,6 +1274,19 @@ bool FancyZones::OnSnapHotkey(DWORD vkCode) noexcept
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FancyZones::ProcessDirectedSnapHotkey(HWND window, DWORD vkCode, bool cycle, winrt::com_ptr<IZoneWindow> zoneWindow) noexcept
|
||||
{
|
||||
// Check whether Alt is used in the shortcut key combination
|
||||
if (GetAsyncKeyState(VK_MENU) & 0x8000)
|
||||
{
|
||||
return m_windowMoveHandler.ExtendWindowByDirectionAndPosition(window, vkCode, zoneWindow);
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_windowMoveHandler.MoveWindowIntoZoneByDirectionAndPosition(window, vkCode, cycle, zoneWindow);
|
||||
}
|
||||
}
|
||||
|
||||
void FancyZones::RegisterVirtualDesktopUpdates(std::vector<GUID>& ids) noexcept
|
||||
{
|
||||
std::unique_lock writeLock(m_lock);
|
||||
|
||||
Reference in New Issue
Block a user