Within emacs, how do I reference the physical screens?
Asked Answered
I

2

7

I have a multi-screen display. Within emacs (GNU Emacs 24.2.1 (i386-mingw-nt6.1.7601) on Windows 7), how can I determine the number of physical screens, and cause things to happen on different screens? For example, I might want to open a new frame in a different screen, or I might want to move the frame in which Emacs is starting to another screen.

Interlaminate answered 6/6, 2013 at 12:0 Comment(0)
A
7

I'm not sure if these functions work on Windows, but on Linux and Mac OS X you can use:

  • x-display-screens: Number of monitors
  • x-display-pixel-width: Current screen (screen that contains Emacs windows) width
  • x-display-pixel-height: Current screen height
  • set-frame-width and set-frame-height: resize
  • set-frame-position: Move frame

For example if you want to create a new frame in another screen, you can do:

(when (and (display-graphic-p) (= (display-screens) 2))
  (make-frame)
  (set-frame-position (selected-frame) 1280 0))

Where 1280 is the width of your first screen.

Alcock answered 6/6, 2013 at 13:7 Comment(7)
You can also take a look at my setup github.com/tungd/dotfiles/blob/master/emacs/init.el#L278Alcock
It looks like x-display-screens doesn't work on my Emacs implementation on Windows. It returns "1 (#o1, #x1)", and I have three screens. Display-screens returns the same thing.Interlaminate
What about x-display-pixel-width? If it returns something like the total width of your screens then that would still be useful.Alcock
Unfortunately, x-display-pixel-width appears to just provide the width of the current screen for Windows.Interlaminate
Have you tried the official binary over here: ftp.gnu.org/gnu/emacs/windows. If that still not working then you might have to wait for 24.4 when native support for this is added (frame-monitor-attributes and display-monitor-attributes-list)Alcock
I haven't yet. Thanks for providing me a giggle. When I looked at that site, I read, "Unfortunately, on Windows 95 and 98, ..." It looks like they need to update their site even more than I need to update my Emacs.Interlaminate
My Emacs does seem to have some awareness of the Windows screens. posn-at-x-y returns "(#<window 3 on .emacs> ..." However, the describe-function on it says "posn-at-x-y is a built-in function in `C source code'", so I don't yet see how I can leverage that to get at the available screens.Interlaminate
S
2

Checkout pos-tip.el code (http://www.emacswiki.org/emacs/pos-tip.el)

It says it works in X and Windows so probably you could find some compatible layer in it.

Stopwatch answered 7/6, 2013 at 17:17 Comment(2)
Thanks for the pointer, but it looks to me that it is using x-display-pixel-width and friends to do screen calculations. I didn't see anything that looked like it was cognizant of Windows screens.Interlaminate
Did you try using it? Why not install and use it first to see if it works?Stopwatch

© 2022 - 2024 — McMap. All rights reserved.