I continuously change the (focus) "order list", and only occasionally explicitely influence (change) the stacking order. The major part of the changes to stacking is done implicitely by WM, as a function of the focus change.
> (window-order) > ;; This is a low level list: > (stacking-order)
Focus can change either by WM command, or by some application (X client). WM has to be ready for both.
Let's treat the 2 cases separately:
This might imply change in WS (workspace). We want to avoid useless restacking (an equivalent of flickering): If we change workspace and present the new WS with some stacking order, and only then raise the focused window, user is confused by the useless movement.
So, if we map or unmap windows, we should do it concious of the necessary restacking: either restack before, or integrate the restacking inside.
switching workspace:
focus the new fwindow, raise its group.
only then map the windows.
focus, raise, map. unmap old workspace, & restack it.