0

In Emacs 23, evaluating

(x-display-pixel-width)

yielded the width of the current window.

In Emacs 24 the same expression returns the combined width of all windows.

How does one return the width of just the main/current window while evaluating the related, but new and improved, function

(display-monitor-attributes-list)

?

Calaf
  • 10,113
  • 15
  • 57
  • 120
  • `(window-width)` -- please note that this is `window`, *not* `frame`. Do you need a more detailed example? E.g., `(with-current-buffer (get-buffer ...` – lawlist Apr 12 '14 at 02:39
  • I'm looking for pixel width, not character width. Also, I'm looking for a measure of the (main) monitor (I'm on OS X). This is for inclusion in .emacs, before the frame is set. – Calaf Apr 12 '14 at 03:27
  • How about the manual at section *28.23 Coordinates and Windows*?: http://www.gnu.org/software/emacs/manual/html_node/elisp/Coordinates-and-Windows.html#Coordinates-and-Windows – lawlist Apr 12 '14 at 03:30

1 Answers1

3

Take a look at display-monitor-attribute-list:

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

Return a list of physical monitor attributes on DISPLAY. Each element of the list represents the attributes of each physical monitor. The first element corresponds to the primary monitor.

Attributes for a physical monitor is 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 workarea 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

where X, Y, WIDTH, and HEIGHT are integers. Keys labeled with (*) are optional.

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-tip frame (including invisible one) in a graphical display is dominated by exactly one physical monitor at a time, though it can span multiple (or no) physical monitors. If DISPLAY is omitted or nil, it defaults to the selected frame's display.

For example, to find the width of the first monitor, you could use:

(nth 4 (assq 'geometry (car (display-monitor-attributes-list))))
Lindydancer
  • 25,428
  • 4
  • 49
  • 68
  • When I try your example in emacs 24, I get `eval: Symbol's function definition is void: display-monitor-attributes-list`. – detly Oct 02 '14 at 00:51