2

I have a two-monitor setup (running Ubuntu).

The Emacs Lisp function display-pixel-width gives me the combined width of the two monitors. How can I get the width of the current monitor (i.e., the monitor displaying the current frame)?

oz1cz
  • 5,504
  • 6
  • 38
  • 58
  • If all else fails, you could probably hack something together using the output from [xrandr](http://linux.die.net/man/1/xrandr). – legoscia May 10 '13 at 13:08

2 Answers2

12

If you are using 24.3 or earlier:

display-pixel-width is a compiled Lisp function in `frame.el'.

(display-pixel-width &optional DISPLAY)

Return the width of DISPLAY's screen in pixels. For character terminals, each character counts as a single pixel.

Additionally, if you are using 24.4 or later:

** Multi-monitor support has been added.

*** New functions display-monitor-attributes-list and frame-monitor-attributes can be used to obtain information about each physical monitor on multi-monitor setups.

Use an external process

You can also parse the output of xwininfo or xrandr (use call-process).

Maximize emacs

Finally, you can maximize emacs (either interactively or using modify-frame-parameters; version 24.4 also has toggle-frame-fullscreen and toggle-frame-maximized) and query its frame size using frame-pixel-height and frame-pixel-width.

See also

  1. How do I find the display size of my system in Emacs?
  2. Can I detect the display size/resolution in Emacs?
sds
  • 58,617
  • 29
  • 161
  • 278
  • No, I'm not using the development version. Perhaps what I want to do is not possible until the `*-monitor-attributes*` functions are available. I certainly have not been able to find an argument to `display-pixel-width` that would give me anything but the combined width of the monitors. Can you perhaps suggest a useful argument? – oz1cz May 10 '13 at 14:22
  • Thank you, @sds. I'll look into either using an external process or maximizing emacs. And then I'll eagerly await version 24.4. :-) – oz1cz May 10 '13 at 18:20
1

display-pixel-width takes an argument to let you specify the display. From its documentation (C-h f display-pixel-width RET):

(display-pixel-width &optional DISPLAY)

Return the width of DISPLAY's screen in pixels. For character terminals, each character counts as a single pixel.

There's also the similar x-display-pixel-width, which may work if the above doesn't.

harpo
  • 41,820
  • 13
  • 96
  • 131
  • That doesn't work for me. According to the documentation, `x-display-pixel-width` may take a `nil` argument, in which case the selected frame's display will be used. Only, on my system I still get the combined width of the monitors when I do `(x-display-pixel-width nil)`, (I'm using emacs 24.2.1.) – oz1cz May 10 '13 at 14:01