microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
111.43k stars 6.56k forks source link

Windows snap override behavior issues and possible solution. #16345

Open derac opened 2 years ago

derac commented 2 years ago

Description of the new feature / enhancement

image

State diagram of desired behavior with Windows Snap override. Criticism of current behavior in supporting information.

A potential algorithm might be the following. The currently selected window can be anywhere on the screen when this runs and it should have good results. This could even take other screens into account. This is essentially better relative mode.

zones = list of zones, with midpoint information if windows_key is pressed and arrow_key_up/down/left/right is pressed:     direction = whichever arrow key was pressed     selected_midpoint = currently selected window's midpoint     using_x_coordinate = if arrow_direction is left or right     using_less_than= if arrow_direction is left or down     if using_x_coordinate:         possible_zones = zones filtered by x being (using_less_than ? <= : >= ) selected_midpoint's x         possible_zones = possible_zones - current zone         target_zone = first element of the list of possible_zones                                 sorted by Euclidean distances to selected_midpoint                                 then y coordinate lowest to highest                                 then zone size biggest to smallest     # add else and use y for x and x for y instead, omitted for brevity     move selected window to target_zone

Scenario when this would be used?

Supporting information

No combination of settings for "Move window based on" gives this behavior. The way this actually works is a mess. Particularly when combining FancyZone land with Windows Snap land by letting it handle up and down. However, with relative position mode, up will never go from left to full. It would be useful to think about the full + half + quarters case as well, as that also cycles between stuff on the left side of the screen and never goes full.

Additionally, the way this feature works when snapping by dragging to the edge is unpredictable as well, as this brings you into Windows Snap land.

Jay-o-Way commented 2 years ago

CC @SeraphimaZ

derac commented 2 years ago

I just realized there is a possible infinite loop when you have two zones with the same midpoint or very close midpoints on the same horizontal or vertical line. I'm not sure how you might resolve that.

derac commented 2 years ago

I thought of a way to get around the infinite looping on near neighbors problem, you could look at a 90 degree quadrant in the direction of the arrow pressed. For midpoints sharing the same exact coordinate, you could store a z-axis and traverse down it when pressing (win+left/down) or up it for (win+up/right). At the bottom or top of the z-axis, respectively you could prefer points not sharing the same coordinates. THEN if there is no matching coordinate, you could search the space in the full half plane (in gray). Though somewhat complicated, I think this aligns really well with user expectations.

I'm getting an idea of how complicated this problem is. I could obviously be totally wrong. Maybe you could just expose a setting for the state diagram of your window layout. :D

image