Lower Other Frame in Emacs

Extending ace-window to lower a chosen frame.

Window management in macOS is quite cumbersome at times. It supports keyboard shortcuts for window switching within an application and for switching between applications, or hiding all the windows for an application. But sometimes it is near-impossible to arrange the windows as desired, e.g. bring one browser window to the foreground but keep an Emacs window in focus.

To work around this I have been thinking about creating Emacs keybindings for raising and lowering specific frames, so at least I have direct control over the frames that I see. Then I realised that I already use ace-window and it already has nearly all the functionality I need.

ace-window allows me to switch to any frame, also raising that frame in the process. All I would need to add is a new dispatch behaviour that lets me lower a specific frame.

It turns out this was just a few lines of code:

(defun my-aw-lower-frame (window)
  "Lower frame containing window."
  (lower-frame (window-frame window)))

(add-to-list 'aw-dispatch-alist '(?l my-aw-lower-frame "Lower Frame"))

The only other extension that might be useful would be a method of raising a frame without selecting it. But there's no obvious way of saving the selected frame before ace-window gets involved.

emacs