Is there a way to programatically work out which display is considered the "primary" display for X within emacs?

I've managed to get a function working that determines if the machine has more than one display connected to it:

(defun how-many-displays ()
    (safe-length (display-monitor-attributes-list)))

I expected that in the list of display attributes, there'd be a way to determine which monitor X thinks is the primary monitor. But unfortunately, the only way to do this seems to be reliant upon defining the monitor layout for each machine I'll be using this config on (which is two machines, but one of them is a laptop that I connect to external displays and as such it will have two configurations).

What I'd like is to be able to determine which display is the primary, and then parse out the geometry so I can calculate offsets for the window position.

Any ideas?

  • I don't know if Emacs provides this info, but you could call xrandr from Emacs and parse the output
    – Tyler
    Oct 12 '19 at 14:23
  • This should be migrated to the Unix and Linux SE site.
    – NickD
    Oct 12 '19 at 15:40
  • 2
    @NickD Why? It's directly related to emacs....
    – NOP
    Oct 12 '19 at 16:48
  • Emacs support for this is rather limited, the best you can do is figuring out what screen a particular frame is on. You could try using xelb if you're hell-bent on directly using X functionality instead of shelling out to xrandr, but honestly, it's not worth the pain.
    – wasamasa
    Oct 12 '19 at 17:21
  • Working out what display the frame is on....how does one accomplish that?
    – NOP
    Oct 12 '19 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.