Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On mac, open an Emacs frame in a specific monitor?

Background: I use a mac with dual monitor. When I start Emacs, it always opens in the “main” monitor (the one on my macbook pro), which is not the one I want to look at. Is there any elisp function to open a new frame in a specific monitor, so that I can have frames in both monitors after emacs starts?

Or, is there any way to let Emacs starts in the external monitor (if it exists)?

BTW, my Emacs is 24.1.1 from emacsforosx.com.

like image 918
MetroWind Avatar asked Jul 12 '12 17:07

MetroWind


1 Answers

The visible area across your displays has a contiguous coordinate space. The top left of the main display (the one with the menu bar on it) is (0, 0). So, opening a frame on a specific display is just a special case of opening a frame in a particular location.

First move the frame where you want it, then use (frame-parameters) to get the top/left values. Normally the result of (frame-parameters) is an alist (list of pairs), something like this:

(... (top . 54) (left . 107) ...)

But if you have displays above or to the left of the main display, the top/left values for windows on that display will be negative. Emacs's GUI support, coming originally from X11, didn't have any concept of negative coordinates. If you try to use negative values, Emacs interprets them as relative to the bottom/right of the main display instead — probably not what you want.

There's a hack in the frame parameter alist to handle this situation: when storing negative top/left values, the corresponding list items are a list of three items instead. For example:

(... (top + -51) (left + -1674) ...)

Normally you can provide these items directly to make-frame, but it doesn't understand this hack. Instead, you can make the frame and immediately move it by modifying its parameters. For example, I've got a 1680x1050 display to the left and slightly above my main display, so this works to display a new frame on that display:

(modify-frame-parameters (make-frame) '((top + -51) (left + -1674)))

Personally I just use Moom, since it's easier to use and more flexible. I create a new frame with C-x 5 2 in Emacs then use Moom keyboard shortcuts to move it to another display, or wherever else I want it.

like image 172
Nicholas Riley Avatar answered Oct 02 '22 15:10

Nicholas Riley