The snapping code is really an unmaintainable mess. Some thoughts on how it might be rewritten:
Situation: 1. There are three different snapping mechanisms: a) Snapping to windows or icons. b) Snapping to screen edges. c) Snapping to the grid. Each one has some distance defined at which snapping will occur. (a) and (b) are set directly, the value for (c) is roughly half the grid size. 2. The top border is in the vicinity of some locations it might snap to: - The bottom border of the next window above it. - The bottom border of the next window below it. - Possibly it's directly on the bottom border. - The top edge of the screen. - The grid line above it. - The grid line below it. 3. There needs to be some algorithm to decide to which of these coordinates the window should be snapped. The current algorithm treats all three mechanisms in separate code which can cause confusing interaction of windows jumping around while moving. The three mechanisms are not equally important. For example, if you have configured that windows whould snap to screen edges at 16 pixels distance, and the grid size is 4, the snap grid should not override the edge snapping at, say, 10 pixels distance. 4. The situation gets much more complicated because the bottom border of the window has completely different coordinates it can snap to. 5. The top or bottom border of the window may be off screen. The window should not snap to objects that are on another page. -- Idea: At a given window position, gather a list of possible snap coordinates and attraction distances for the top border (2). Gather a similar list for the bottom border (4). The list for the bottom border can actually be recalculated into top border coordinates (if the bottom coordinate is y, the top coordinate is (y - window height)). Now run the algorithm (3) to decide which coordinate shall be used for snapping. Treat window borders and screen edges as equally important. Whatever value is closest is shosen. Snap to the grid only if the window was not snapped to another window, icon or screen edge, Ciao Dominik ^_^ ^_^ -- Dominik Vogt