mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[FancyZones] Hold Ctrl to select any number of zones (#4850)
* Started work * Did something, not yet sure that it works * Sort of works * Cleari highlighted zones when using Ctrl after leaving a monitor * Remove unnecessary line * Enhanced UX. Maybe refactor? * Changed the logic behind zone selection when dragging * Various fixups
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include "lib/util.h"
|
||||
#include "VirtualDesktopUtils.h"
|
||||
#include "lib/SecondaryMouseButtonsHook.h"
|
||||
#include <lib/ShiftKeyHook.h>
|
||||
#include "lib/GenericKeyHook.h"
|
||||
|
||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
@@ -48,10 +48,13 @@ namespace WindowMoveHandlerUtils
|
||||
class WindowMoveHandlerPrivate
|
||||
{
|
||||
public:
|
||||
WindowMoveHandlerPrivate(const winrt::com_ptr<IFancyZonesSettings>& settings, SecondaryMouseButtonsHook* mouseHook, ShiftKeyHook* shiftHook) :
|
||||
WindowMoveHandlerPrivate(const winrt::com_ptr<IFancyZonesSettings>& settings, SecondaryMouseButtonsHook* mouseHook, ShiftKeyHook* shiftHook, CtrlKeyHook* ctrlHook) :
|
||||
m_settings(settings),
|
||||
m_mouseHook(mouseHook),
|
||||
m_shiftHook(shiftHook){};
|
||||
m_shiftHook(shiftHook),
|
||||
m_ctrlHook(ctrlHook)
|
||||
{
|
||||
}
|
||||
|
||||
bool IsDragEnabled() const noexcept
|
||||
{
|
||||
@@ -65,6 +68,7 @@ public:
|
||||
|
||||
void OnMouseDown() noexcept;
|
||||
void OnShiftChangeState(bool state) noexcept;
|
||||
void OnCtrlChangeState(bool state) noexcept;
|
||||
|
||||
void MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map<HMONITOR, winrt::com_ptr<IZoneWindow>>& zoneWindowMap) noexcept;
|
||||
void MoveSizeUpdate(HMONITOR monitor, POINT const& ptScreen, const std::unordered_map<HMONITOR, winrt::com_ptr<IZoneWindow>>& zoneWindowMap) noexcept;
|
||||
@@ -80,6 +84,7 @@ private:
|
||||
winrt::com_ptr<IFancyZonesSettings> m_settings{};
|
||||
SecondaryMouseButtonsHook* m_mouseHook{};
|
||||
ShiftKeyHook* m_shiftHook{};
|
||||
CtrlKeyHook* m_ctrlHook{};
|
||||
|
||||
HWND m_windowMoveSize{}; // The window that is being moved/sized
|
||||
bool m_inMoveSize{}; // Whether or not a move/size operation is currently active
|
||||
@@ -87,10 +92,11 @@ private:
|
||||
bool m_dragEnabled{}; // True if we should be showing zone hints while dragging
|
||||
bool m_secondaryMouseButtonState{}; // True when secondary mouse button was clicked after window was moved
|
||||
bool m_shiftKeyState{}; // True when shift key was pressed after window was moved
|
||||
bool m_ctrlKeyState{}; // True when ctrl key was pressed after window was moved
|
||||
};
|
||||
|
||||
WindowMoveHandler::WindowMoveHandler(const winrt::com_ptr<IFancyZonesSettings>& settings, SecondaryMouseButtonsHook* mouseHook, ShiftKeyHook* shiftHook) :
|
||||
pimpl(new WindowMoveHandlerPrivate(settings, mouseHook, shiftHook)) {}
|
||||
WindowMoveHandler::WindowMoveHandler(const winrt::com_ptr<IFancyZonesSettings>& settings, SecondaryMouseButtonsHook* mouseHook, ShiftKeyHook* shiftHook, CtrlKeyHook* ctrlHook) :
|
||||
pimpl(new WindowMoveHandlerPrivate(settings, mouseHook, shiftHook, ctrlHook)) {}
|
||||
|
||||
WindowMoveHandler::~WindowMoveHandler()
|
||||
{
|
||||
@@ -117,6 +123,11 @@ void WindowMoveHandler::OnShiftChangeState(bool state) noexcept
|
||||
pimpl->OnShiftChangeState(state);
|
||||
}
|
||||
|
||||
void WindowMoveHandler::OnCtrlChangeState(bool state) noexcept
|
||||
{
|
||||
pimpl->OnCtrlChangeState(state);
|
||||
}
|
||||
|
||||
void WindowMoveHandler::MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map<HMONITOR, winrt::com_ptr<IZoneWindow>>& zoneWindowMap) noexcept
|
||||
{
|
||||
pimpl->MoveSizeStart(window, monitor, ptScreen, zoneWindowMap);
|
||||
@@ -152,6 +163,11 @@ void WindowMoveHandlerPrivate::OnShiftChangeState(bool state) noexcept
|
||||
m_shiftKeyState = state;
|
||||
}
|
||||
|
||||
void WindowMoveHandlerPrivate::OnCtrlChangeState(bool state) noexcept
|
||||
{
|
||||
m_ctrlKeyState = state;
|
||||
}
|
||||
|
||||
void WindowMoveHandlerPrivate::MoveSizeStart(HWND window, HMONITOR monitor, POINT const& ptScreen, const std::unordered_map<HMONITOR, winrt::com_ptr<IZoneWindow>>& zoneWindowMap) noexcept
|
||||
{
|
||||
if (!IsInterestingWindow(window, m_settings->GetSettings()->excludedAppsArray) || WindowMoveHandlerUtils::IsCursorTypeIndicatingSizeEvent())
|
||||
@@ -175,6 +191,7 @@ void WindowMoveHandlerPrivate::MoveSizeStart(HWND window, HMONITOR monitor, POIN
|
||||
}
|
||||
|
||||
m_shiftHook->enable();
|
||||
m_ctrlHook->enable();
|
||||
|
||||
// This updates m_dragEnabled depending on if the shift key is being held down.
|
||||
UpdateDragState(window);
|
||||
@@ -247,6 +264,7 @@ void WindowMoveHandlerPrivate::MoveSizeUpdate(HMONITOR monitor, POINT const& ptS
|
||||
{
|
||||
// The drag has moved to a different monitor.
|
||||
m_zoneWindowMoveSize->RestoreOriginalTransparency();
|
||||
m_zoneWindowMoveSize->ClearSelectedZones();
|
||||
|
||||
if (!m_settings->GetSettings()->showZonesOnAllMonitors)
|
||||
{
|
||||
@@ -258,7 +276,7 @@ void WindowMoveHandlerPrivate::MoveSizeUpdate(HMONITOR monitor, POINT const& ptS
|
||||
|
||||
for (auto [keyMonitor, zoneWindow] : zoneWindowMap)
|
||||
{
|
||||
zoneWindow->MoveSizeUpdate(ptScreen, m_dragEnabled);
|
||||
zoneWindow->MoveSizeUpdate(ptScreen, m_dragEnabled, m_ctrlKeyState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,6 +299,7 @@ void WindowMoveHandlerPrivate::MoveSizeEnd(HWND window, POINT const& ptScreen, c
|
||||
|
||||
m_mouseHook->disable();
|
||||
m_shiftHook->disable();
|
||||
m_ctrlHook->disable();
|
||||
|
||||
m_inMoveSize = false;
|
||||
m_dragEnabled = false;
|
||||
|
||||
Reference in New Issue
Block a user