2

I tried querying the display width using:

(display-pixel-width)

however this reports the pixel width of my external monitor instead of the laptop's display, where emacs is.

Is there a way to show the information of the display where emacs currently is?

Edit: for the time being I'm using frame-monitor-attributes as follows:

(nth 3 (assq 'geometry (frame-monitor-attributes)))

This reports the display width of the monitor emacs is in, instead of always showing the width of the external monitor.

2
  • 1
    You have to give it the display or frame as argument, otherwise it uses the display of the selected frame.
    – NickD
    Commented Sep 17, 2020 at 12:34
  • But how do I know the display emacs is currently in? I couldn't even figure out what to pass as argument. Commented Sep 22, 2020 at 8:04

1 Answer 1

2

As @NickD said in a comment, display-pixel-width uses the current display/frame by default, but you can provide the one you want to consider as an argument.

There is also function display-monitor-attributes-list, which gives you quite a lot of info. C-h f tells us:

display-monitor-attributes-list is a compiled Lisp function in frame.el.

(display-monitor-attributes-list &optional DISPLAY)

Return a list of physical monitor attributes on DISPLAY.

DISPLAY can be a display name, a terminal name, or a frame. If DISPLAY is omitted or nil, it defaults to the selected frame's display. Each element of the list represents the attributes of a physical monitor. The first element corresponds to the primary monitor.

The attributes for a physical monitor are represented as an alist of attribute keys and values as follows:

geometry -- Position and size in pixels in the form of (X Y WIDTH HEIGHT)
workarea -- Position and size of the work area in pixels in the form of (X Y WIDTH HEIGHT)
mm-size  -- Width and height in millimeters in the form of (WIDTH HEIGHT)
frames   -- List of frames dominated by the physical monitor
name (*) -- Name of the physical monitor as a string
source (*) -- Source of multi-monitor information as a string

where X, Y, WIDTH, and HEIGHT are integers. X and Y are coordinates of the top-left corner, and might be negative for monitors other than the primary one. Keys labeled with (*) are optional.

The "work area" is a measure of the "usable" display space. It may be less than the total screen size, owing to space taken up by window manager features (docks, taskbars, etc.). The precise details depend on the platform and environment.

The source attribute describes the source from which the information was obtained. On X, this may be one of: "Gdk", "XRandr", "Xinerama", or "fallback".

A frame is dominated by a physical monitor when either the largest area of the frame resides in the monitor, or the monitor is the closest to the frame if the frame does not intersect any physical monitors. Every (non-tooltip) frame (including invisible ones) in a graphical display is dominated by exactly one physical monitor at a time, though it can span multiple (or no) physical monitors.

7
  • Thanks. The problem is that I do not know what to pass as argument, and also this depends on the display emacs is in. Commented Sep 22, 2020 at 8:05
  • The doc string tells you what the argument DISPLAY needs to be. And if you omit it then the selected frame is used, that is, the display showing that frame is used. Did you try just omitting the argument?
    – Drew
    Commented Sep 22, 2020 at 21:46
  • I only managed to call it without argument, so yes. In this case I always got the dimensions of the external monitor, regardless of where I placed the emacs windows. Commented Sep 23, 2020 at 12:31
  • And my problem with providing a display value is that I do not know which string should I fill in, or where to get the valid values from. Commented Sep 23, 2020 at 12:33
  • 1
    Sounds like a bug, to me. But I'm no expert on this. Use M-x report-emacs-bug, if no one provides a good answer here soon. Emacs developers will be able to determine whether there's actually a bug etc.
    – Drew
    Commented Sep 25, 2020 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.