On Sat, Nov 20, 2021 at 04:17:41PM -0700, Jaimos Skriletz wrote: > On Sun, Nov 14, 2021 at 10:57 AM Dominik Vogt <dominik.v...@gmx.de> wrote: > > > > The snapping code is really an unmaintainable mess. Some thoughts > > on how it might be rewritten: > > > > Here are some thoughts I have, you can see them in js/snapattract branch. > > I have split the three different snapping checks into individual > functions for Monitor Edges, Windows, and Grid. I have then set up a > priority of Monitor > Windows > Grid, so this way when something is > found to snap too, it stops looking for other things based on the > priority, and this should stop some of the strange interactions > between deciding what to snap too. I also treat horizontal and > vertical independently so it can snap to both a window and a monitor > edge in different directions. Currently the priority is hardcoded, but > since the checks are now individual functions, it could be possible to > set it up so the user can configure what snap priority. Comments > welcome.
Thanks! It looks much cleaner now (not tested though). Some comments: 1) Can we safely assume that the "bool" C type is available in every relevant compiler? 2) Please break up the calculations in DoSnapGrid into multiple lines unsing temp variable. It's too hard to read = hard to maintain. The previous un-readability of the code shouldn't be the standard we aim at. ;-) 3) Same for "smap_mon = ...". Ouch. 4) I'm not sure whether screen boundaries should have a higher priority than windows and not equal priorities. That would require scoring. For example, if a window on (0 0) is fullscreen so that the borders are on the adjacent pages. Then you couldn't align a window on (0 1) with that window border because snapping to the screen edge always wins. Shouldn't be too difficult to implement; the new sub functions would simply return a score = the absolute snapping distance that was used, and the lowest one wins. (Gird is still only used if there was no other snapping.) 5) Edge resistance is a kind of reverse snapping with a different snap distance: A window that has been moved past the screen edge "snaps" back until it has moved more than the edge resistance past the edge. This is exactly what snapattraction does, just with the snap distance from a different variable. Can that be merged with the new code? Ciao Dominik ^_^ ^_^ -- Dominik Vogt