-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add Grab And Move middle-click maximize #48483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Azotlikide
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
Azotlikide:codex/grabandmove-middle-click-maximize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,7 +247,7 @@ | |
| | Event Name | Description | | ||
| | --- | --- | | ||
| | Microsoft.PowerToys.GrabAndMove_EnableGrabAndMove | Triggered when Grab And Move is enabled or disabled. | | ||
| | Microsoft.PowerToys.GrabAndMove_ShortcutUse | Logs an attempt to move or resize a window via the Alt+Drag shortcut, including whether it succeeded, the action type (move or resize), and the reason (e.g., started, blocked by game mode). | | ||
| | Microsoft.PowerToys.GrabAndMove_ShortcutUse | Logs an attempt to move, resize, or maximize/restore a window via Grab And Move mouse shortcuts, including whether it succeeded, the action type (move, resize, or maximize), and the reason (e.g., started, toggled, blocked by game mode, or not maximizable). | | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
maximizable is not a recognized word
|
||
|
|
||
| ### Hosts File Editor | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,9 @@ | |
| static bool g_showGeometry = false; // true if we want to draw the X, Y, W and H on the overlay on move and resize | ||
| static bool g_doNotActivateOnGameMode = true; // true if GrabAndMove is suppressed when Windows Game Mode is active | ||
|
|
||
| static bool g_useAltResize = true; // This can be toggled from the settings. If false, Alt + right click does nothing. | ||
| static bool g_useAltResize = true; // This can be toggled from the settings. If false, Alt + right click does nothing. | ||
| static bool g_useMiddleClickMaximize = true; // If true, modifier + middle click toggles maximize/restore. | ||
| static bool g_middleClickConsumed = false; // Swallow the matching middle-button release after a handled press. | ||
|
|
||
| // Count of non-modifier keys currently held. Used to suppress GrabAndMove when the | ||
| // modifier key is pressed while another key is already down (e.g. Q held, then modifier pressed). | ||
|
|
@@ -225,11 +227,23 @@ | |
| { | ||
| Move, | ||
| Resize, | ||
| Maximize, | ||
| }; | ||
|
|
||
| static void TraceShortcutUse(bool successful, GrabAndMoveShortcutAction action, const wchar_t* reason) noexcept | ||
| { | ||
| const wchar_t* actionName = action == GrabAndMoveShortcutAction::Move ? L"move" : L"resize"; | ||
| const wchar_t* actionName = L"move"; | ||
| switch (action) | ||
| { | ||
| case GrabAndMoveShortcutAction::Resize: | ||
| actionName = L"resize"; | ||
| break; | ||
| case GrabAndMoveShortcutAction::Maximize: | ||
| actionName = L"maximize"; | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
| TraceLoggingWrite( | ||
| g_hProvider, | ||
|
|
@@ -241,6 +255,22 @@ | |
| TraceLoggingWideString(reason, "Reason")); | ||
| } | ||
|
|
||
| static bool IsWindowMaximizable(HWND hwnd) | ||
| { | ||
| return (GetWindowLongPtrW(hwnd, GWL_STYLE) & WS_MAXIMIZEBOX) != 0; | ||
| } | ||
|
|
||
| static bool ToggleWindowMaximized(HWND hwnd) | ||
| { | ||
| if (!hwnd || !IsWindowMaximizable(hwnd)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| ShowWindow(hwnd, IsZoomed(hwnd) ? SW_RESTORE : SW_MAXIMIZE); | ||
| return true; | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Settings file helpers | ||
| // --------------------------------------------------------------------------- | ||
|
|
@@ -270,6 +300,11 @@ | |
| g_useAltResize = *v; | ||
| } | ||
|
|
||
| if (auto v = values.get_bool_value(L"useMiddleClickMaximize")) | ||
| { | ||
| g_useMiddleClickMaximize = *v; | ||
| } | ||
|
|
||
| if (auto v = values.get_int_value(L"modifierKey")) | ||
| { | ||
| g_modifierKey = (*v == 1) ? GrabAndMoveModifier::Win : GrabAndMoveModifier::Alt; | ||
|
|
@@ -1011,16 +1046,52 @@ | |
| goto forward; | ||
|
|
||
| // Recovery path: if a non-modifier click occurs while stale drag/resize state exists, clear it. | ||
| if ((wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN) && !IsActivationModifierPressed()) | ||
| if ((wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN || wParam == WM_MBUTTONDOWN) && !IsActivationModifierPressed()) | ||
| { | ||
| EndInteraction(true, true); | ||
| } | ||
|
|
||
| if (wParam == WM_MBUTTONUP && g_middleClickConsumed) | ||
| { | ||
| g_middleClickConsumed = false; | ||
| return 1; | ||
| } | ||
|
|
||
| if (!g_dragging && !g_resizing && g_hOverlay && IsWindowVisible(g_hOverlay)) | ||
| { | ||
| HideOverlay(); | ||
| } | ||
|
|
||
| // ----- Alt + Middle Button Down: toggle maximize/restore ----- | ||
| if (wParam == WM_MBUTTONDOWN && g_useMiddleClickMaximize && IsActivationModifierPressed()) | ||
| { | ||
| if (IsSuppressedByGameMode()) | ||
| { | ||
| TraceShortcutUse(false, GrabAndMoveShortcutAction::Maximize, L"game_mode"); | ||
| goto forward; | ||
| } | ||
|
|
||
| POINT pt = ms->pt; | ||
| HWND hwnd = ResolveTargetWindow(pt); | ||
| if (hwnd) | ||
| { | ||
| if (IsExcluded(hwnd)) | ||
| { | ||
| goto forward; | ||
| } | ||
|
|
||
| if (ToggleWindowMaximized(hwnd)) | ||
| { | ||
| g_dragConsumedAlt = true; | ||
| g_middleClickConsumed = true; | ||
| TraceShortcutUse(true, GrabAndMoveShortcutAction::Maximize, L"toggled"); | ||
| return 1; | ||
| } | ||
|
|
||
| TraceShortcutUse(false, GrabAndMoveShortcutAction::Maximize, L"not_maximizable"); | ||
Check failureCode scanning / check-spelling Unrecognized Spelling Error
maximizable is not a recognized word
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| } | ||
| } | ||
|
|
||
| // ----- Alt + Left Button Down: start drag ----- | ||
| if (wParam == WM_LBUTTONDOWN && IsActivationModifierPressed()) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/settings-ui/Settings.UI.UnitTests/ViewModelTests/GrabAndMove.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Copyright (c) Microsoft Corporation | ||
| // The Microsoft Corporation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Text.Json; | ||
| using Microsoft.PowerToys.Settings.UI.Library; | ||
| using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks; | ||
| using Microsoft.PowerToys.Settings.UI.ViewModels; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| namespace ViewModelTests | ||
| { | ||
| [TestClass] | ||
| public class GrabAndMove | ||
| { | ||
| [TestMethod] | ||
| public void MiddleClickMaximizeIsEnabledByDefault() | ||
| { | ||
| var settings = new GrabAndMoveSettings(); | ||
|
|
||
| Assert.IsTrue(settings.Properties.UseMiddleClickMaximize.Value); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void UpdatingMiddleClickMaximizeNotifiesRunner() | ||
| { | ||
| var moduleSettings = new GrabAndMoveSettings(); | ||
| string serializedSettings = string.Empty; | ||
|
|
||
| using var viewModel = new GrabAndMoveViewModel( | ||
| SettingsRepository<GeneralSettings>.GetInstance(ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>().Object), | ||
| moduleSettings, | ||
| msg => | ||
| { | ||
| serializedSettings = msg; | ||
| return 0; | ||
| }); | ||
|
|
||
| viewModel.UseMiddleClickMaximize = false; | ||
|
|
||
| var outgoingSettings = JsonSerializer.Deserialize<SndModuleSettings<SndGrabAndMoveSettings>>(serializedSettings); | ||
| Assert.IsFalse(outgoingSettings!.PowertoysSetting.Settings.Properties.UseMiddleClickMaximize.Value); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.