Cinnamon-like / Aerosnap tiling finction

I’m trying to write a Cinnamon-like pseudo tiling function which makes use of the keyboard to quickly resize and move windows to and from various fixed positions, with window states 1-9 representing the positions as they would on a numpad I.E. 1 = lower-left corner; 9 = upper-right corner; 2 = bottom half of screen; 8 = top half of screen; 6 = right half of screen; 3 = bottom-right corner; etc.

In theory it should work like this:
WinKey + Arrow = Tiles window to given part of the screen (Another arrow moves window to next tiled position or untiles and returns window to original position, depending on given direction)

So far I am able put the windows into, and return to the original position from, positions 2, 4, 6, 8, I.E. all the “half screen” positions.

But I cannot reliably get the corner positions to work (1,3,7,9). Sometimes the windows go into those positions, sometimes not, and even if they do, it is not always the corner I designate, nor does it “come out” of the corner.

As an illustration, I can put the window into position 6 (right half of screen), and then move it down into position 3 (bottom-right corner), but then it just gets stuck there. Also, If I put a window into position 4 (left-half of screen) and move it down into position 1 (bottom-left of screen) it jumps to position 3 (bottom-right of screen). I can’t work out what is wrong.

(I have used ResizeMoveMaximize in order to have the ability to return the window to it’s original position, and have designated “State 5” to be used for all windows being tiled, so my other windows are not interfered with.)

Here are my functions]
DestroyFunc TileLeft
AddToFunc TileLeft

if tiled and tiled left (up, middle or down) then do nothing

  • I Current (State 5, State 1) Break
  • I Current (State 5, State 4) Break
  • I Current (State 5, State 7) Break

If not tiled, tile left, give tiled state and tiled left state

  • I Current (!State 5, !Maximized) ResizeMoveMaximize 50 100 0 0
  • I Current (!State 5) State 4
  • I Current (!State 5) State 5
  • I TestRc (Match) Break

If tiled right, then untile and remove tiled states

  • I Current (State 5, State 6) Maximize False
  • I State 6 False
  • I State 5 False
  • I TestRc (Match) Break

If tiled up, then tile top-left

  • I Current (State 5, State 8) Maximize False
  • I State 8 False
  • I State 7 True
  • I Current (State 7) ResizeMoveMaximize 50 50 0 0
  • I TestRc (Match) Break

If tiled bottom, then tile bottom-left

  • I Current (State 5, State 2) Maximize False
  • I State 2 False
  • I State 1 True
  • I Current (State 1) ResizeMoveMaximize 50 50 0 50
  • I TestRc (Match) Break

If tiled top-right, then tile top

  • I Current (State 5, State 9) Maximize False
  • I State 9 False
  • I State 8 True
  • I Current (State 8) ResizeMoveMaximize 100 50 0 0
  • I TestRc (Match) Break

If tiled bottom-right, then tile bottom

  • I Current (State 5, State 3) Maximize False
  • I State 3 False
  • I State 2 True
  • I Current (State 2) ResizeMoveMaximize 100 50 0 50
  • I TestRc (Match) Break
    Key Left A 4 TileLeft

DestroyFunc TileRight
AddToFunc TileRight

if tiled and tiled right (up, middle or down) then do nothing

  • I Current (State 5, State 3) Break
  • I Current (State 5, State 6) Break
  • I Current (State 5, State 9) Break

If not tiled, tile right, give tiled state and tiled right state

  • I Current (!State 5, !Maximized) ResizeMoveMaximize 50 100 50 0
  • I Current (!State 5) State 6
  • I Current (!State 5) State 5
  • I TestRc (Match) Break

If tiled left, then untile and remove tiled states

  • I Current (State 5, State 4) Maximize False
  • I State 4 False
  • I State 5 False
  • I TestRc (Match) Break

If tiled top, then tile top-right

  • I Current (State 5, State 8) Maximize False
  • I State 8 False
  • I State 9 True
  • I Current (State 9) ResizeMoveMaximize 50 50 50 0
  • I TestRc (Match) Break

If tiled bottom, then tile bottom-right

  • I Current (State 5, State 2) Maximize False
  • I State 2 False
  • I State 3 True
  • I Current (State 3) ResizeMoveMaximize 50 50 50 50
  • I TestRc (Match) Break

If tiled top-left, then tile top

  • I Current (State 5, State 7) Maximize False
  • I State 7 False
  • I State 8 True
  • I Current (State 8) ResizeMoveMaximize 100 50 0 0
  • I TestRc (Match) Break

If tiled bottom-left, then tile bottom

  • I Current (State 5, State 1) Maximize False
  • I State 1 False
  • I State 2 True
  • I Current (State 2) ResizeMoveMaximize 100 50 0 50
  • I TestRc (Match) Break
    Key Right A 4 TileRight

DestroyFunc TileUp
AddToFunc TileUp

if tiled and tiled up (left, middle or right) then do nothing

  • I Current (State 5, State 7) Break
  • I Current (State 5, State 8) Break
  • I Current (State 5, State 9) Break

If not tiled, tile up, give tiled state and tiled up state

  • I Current (!State 5, !Maximized) ResizeMoveMaximize 100 50 0 0
  • I Current (!State 5) State 8
  • I Current (!State 5) State 5
  • I TestRc (Match) Break

If tiled down, then untile and remove tiled states

  • I Current (State 5, State 2) Maximize False
  • I State 2 False
  • I State 5 False
  • I TestRc (Match) Break

If tiled right, then tile top-right

  • I Current (State 5, State 6) Maximize False
  • I State 6 False
  • I State 9 True
  • I Current (State 9) ResizeMoveMaximize 50 50 50 0
  • I TestRc (Match) Break

If tiled left, then tile top-left

  • I Current (State 5, State 4) Maximize False
  • I State 4 False
  • I State 7 True
  • I Current (State 7) ResizeMoveMaximize 50 50 0 0
  • I TestRc (Match) Break

If tiled bottom-right, then tile right

  • I Current (State 5, State 3) Maximize False
  • I State 3 False
  • I State 6 True
  • I Current (State 6) ResizeMoveMaximize 50 100 50 0
  • I TestRc (Match) Break

If tiled bottom-left, then tile left

  • I Current (State 5, State 1) Maximize False
  • I State 1 False
  • I State 4 True
  • I Current (State 4) ResizeMoveMaximize 50 100 0 0
  • I TestRc (Match) Break
    Key Up A 4 TileUp

DestroyFunc TileDown
AddToFunc TileDown

if tiled and tiled down (left, middle or right) then do nothing

  • I Current (State 5, State 1) Break
  • I Current (State 5, State 2) Break
  • I Current (State 5, State 3) Break

If not tiled, tile down, give tiled state and tiled down state

  • I Current (!State 5, !Maximized) ResizeMoveMaximize 100 50 0 50
  • I Current (!State 5) State 2
  • I Current (!State 5) State 5
  • I TestRc (Match) Break

If tiled up, then untile and remove tiled states

  • I Current (State 5, State 8) Maximize False
  • I State 8 False
  • I State 5 False
  • I TestRc (Match) Break

If tiled right, then tile bottom-right

  • I Current (State 5, State 6) Maximize False
  • I State 6 False
  • I State 3 True
  • I Current (State 3) ResizeMoveMaximize 50 50 50 50
  • I TestRc (Match) Break

If tiled left, then tile bottom-left

  • I Current (State 5, State 4) Maximize False
  • I State 4 False
  • I State 1 True
  • I Current (State 1) ResizeMoveMaximize 50 50 0 50
  • I TestRc (Match) Break

If tiled top-right, then tile right

  • I Current (State 5, State 9) Maximize False
  • I State 9 False
  • I State 6 True
  • I Current (State 6) ResizeMoveMaximize 50 100 50 0
  • I TestRc (Match) Break

If tiled top-left, then tile left

  • I Current (State 5, State 7) Maximize False
  • I State 7 False
  • I State 4 True
  • I Current (State 4) ResizeMoveMaximize 50 100 0 0
  • I TestRc (Match) Break
    Key Down A 4 TileDown
    [/code]

Any help is much appreciated. Thanks.

Hallo, n0nr4nd0m,
I hope you haven’t lost patience yet. Your “stateful” logic is, in fact, wrong. I didn’t overlook it completely, but when I follow your given example, first to 6 and from there to 3, I really end up with a State 3 set but a State 5 unset, i. e. you’re stuck.
You must simplify this logic somehow. My suggestion is to write three more functions, “ClearBits”, “UnTile” and “Tile”.

  • ClearBits clears all State bits, including no. 5
  • UnTile calls ClearBits and unmaximizes the window
  • Tile serves to freshly tile or to re-tile a window. It gets 5 arguments: the wanted State number and the 4 parameters for ResizeMoveMaximize. It calls ClearBits, sets State 5, sets State $0 and calls ResizeMoveMaximize. You can call ResizeMoveMaximize for an already maximized window btw., no need to unmaximize first.
    Your four functions TileLeft etc. only decide whether to Break or to call Tile or UnTile.
    This doesn’t make it shorter but better to debug.

I’ve finally got round to doing it. Works fine. Here is what I’ve got:

[code]DestroyFunc TileFunc
AddToFunc TileFunc

  • I Function ClearTileStatesFunc
  • I State $0 True
  • I ResizeMoveMaximize Frame $1 $2 $3 $4

DestroyFunc ClearTileStatesFunc
AddToFunc ClearTileStatesFunc

  • I State 1 False
  • I State 2 False
  • I State 3 False
  • I State 4 False
  • I State 5 False
  • I State 6 False
  • I State 7 False
  • I State 8 False
  • I State 9 False

DestroyFunc UnTileFunc
AddToFunc UnTileFunc

  • I Maximize False
  • I Function ClearTileStatesFunc

DestroyFunc TileLeftFunc
AddToFunc TileLeftFunc

if not tiled, tile left

  • I Current (!State 1, !State 2, !State 3, !State 4, !State 5, !State 6, !State 7, !State 8, !State 9, !State 10) Function TileFunc 4 50 100 0 0
  • I TestRc (Match) Break

if tiled bottom-left, do nothing

  • I Current (State 1) Break

if tiled bottom, then tile bottom-left

  • I Current (State 2) Function TileFunc 1 50 50 0 50
  • I State 2 False
  • I TestRc (Match) Break

if tiled bottom-right, then tile bottom

  • I Current (State 3) Function TileFunc 2 100 50 0 50
  • I State 3 False
  • I TestRc (Match) Break

if tiled left, do nothing

  • I Current (State 4) Function TileFunc 4 25 100 0 0

if tiled middle, tile left

  • I Current (State 5) Function TileFunc 4 50 100 0 0
  • I State 5 False
  • I TestRc (Match) Break

if tiled right, then untile and remove tiled states

  • I Current (State 6) Function UnTileFunc
  • I TestRc (Match) Break

if tiled top-left, do nothing

  • I Current (State 7) Break

if tiled up, then tile top-left

  • I Current (State 8) Function TileFunc 7 50 50 0 0
  • I State 8 False
  • I TestRc (Match) Break

if tiled top-right, then tile top

  • I Current (State 9) Function TileFunc 8 100 50 0 0
  • I State 9 False
  • I TestRc (Match) Break

DestroyFunc TileRightFunc
AddToFunc TileRightFunc

if not tiled, tile right

  • I Current (!State 1, !State 2, !State 3, !State 4, !State 5, !State 6, !State 7, !State 8, !State 9, !State 10) Function TileFunc 6 50 100 50 0
  • I TestRc (Match) Break

if tiled bottom-left, tile to bottom

  • I Current (State 1) Function TileFunc 2 100 50 0 50
  • I State 1 False
  • I TestRc (Match) Break

if tiled bottom, then tile bottom-right

  • I Current (State 2) Function TileFunc 3 50 50 50 50
  • I State 2 False
  • I TestRc (Match) Break

if tiled bottom-right, then do nothing

  • I Current (State 3) Break

if tiled left, then untile

  • I Current (State 4) Function UnTileFunc
  • I TestRc (Match) Break

if tiled middle, tile right

  • I Current (State 5) Function TileFunc 6 50 100 50 0
  • I State 5 False
  • I TestRc (Match) Break

if tiled right, then do nothing

  • I Current (State 6) Function TileFunc 6 25 100 75 0

if tiled top-left, then tile top

  • I Current (State 7) Function TileFunc 8 100 50 0 0
  • I TestRc (Match) Break

if tiled up, then tile top-right

  • I Current (State 8) Function TileFunc 9 50 50 50 0
  • I State 8 False
  • I TestRc (Match) Break

if tiled top-right, then do nothing

  • I Current (State 9) Break

DestroyFunc TileUpFunc
AddToFunc TileUpFunc

if not tiled, tile up

  • I Current (!State 1, !State 2, !State 3, !State 4, !State 5, !State 6, !State 7, !State 8, !State 9, !State 10) Function TileFunc 5 100 100 0 0
  • I TestRc (Match) Break

if tiled bottom-left, tile to left

  • I Current (State 1) Function TileFunc 4 50 100 0 0
  • I State 1 False
  • I TestRc (Match) Break

if tiled bottom, then untile

  • I Current (State 2) Function UnTileFunc
  • I TestRc (Match) Break

if tiled bottom-right, then tile right

  • I Current (State 3) Function TileFunc 6 50 100 50 0
  • I State 3 False
  • I TestRc (Match) Break

if tiled left, then tile top left

  • I Current (State 4) Function TileFunc 7 50 50 0 0
  • I State 4 False
  • I TestRc (Match) Break

if tiled middle, tile up

  • I Current (State 5) Function TileFunc 8 100 50 0 0
  • I State 5 False
  • I TestRc (Match) Break

if tiled right, then tile top right

  • I Current (State 6) Function TileFunc 9 50 50 50 0
  • I State 6 False
  • I TestRc (Match) Break

if tiled top-left, then do nothing

  • I Current (State 7) Break

if tiled up, then do nothing

  • I Current (State 8) Break

if tiled top-right, then do nothing

  • I Current (State 9) Break

if tiled fullscreen, then tile top

  • I Current (State 5) Function TileFunc 8 100 50 0 0
  • I State 5 False
  • I TestRc (Match) Break

DestroyFunc TileDownFunc
AddToFunc TileDownFunc

if not tiled, tile down

  • I Current (!State 1, !State 2, !State 3, !State 4, !State 5, !State 6, !State 7, !State 8, !State 9, !State 10) Function TileFunc 2 100 50 0 50
  • I TestRc (Match) Break

if tiled bottom-left, do nothing

  • I Current (State 1) Break

if tiled bottom, do nothing

  • I Current (State 2) Break

if tiled bottom-right, then do nothing

  • I Current (State 3) Break

if tiled left, then tile bottom left

  • I Current (State 4) Function TileFunc 1 50 50 0 50
  • I State 4 False
  • I TestRc (Match) Break

if tiled middle, tile down

  • I Current (State 5) Function UnTileFunc
  • I State 5 False
  • I TestRc (Match) Break

if tiled right, then tile bottom right

  • I Current (State 6) Function TileFunc 3 50 50 50 50
  • I State 6 False
  • I TestRc (Match) Break

if tiled top-left, then tile left

  • I Current (State 7) Function TileFunc 4 50 100 0 0
  • I State 7 False
  • I TestRc (Match) Break

if tiled up, then tile to fullscreen

  • I Current (State 8) Function TileFunc 5 100 100 0 0
  • I State 8 False
  • I TestRc (Match) Break

if tiled top-right, then tile right

  • I Current (State 9) Function TileFunc 6 50 100 50 0
  • I State 9 False
  • I TestRc (Match) Break
    [/code]