Use the same gravity calculation everywhere

This also enables the use of :top, :bottom, :left and :right gravity for
the message and input window.