unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* (x-display-pixel-height)
@ 2022-05-18 22:56 Perry Smith
  2022-05-19  1:05 ` (x-display-pixel-height) Po Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Perry Smith @ 2022-05-18 22:56 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2254 bytes --]

I’m using a Mac laptop and can plug in a second monitor.

I’m also using two instances of Emacs 28.1.  One I built on macOS with NextStep support.  The other I build on Free BSD with X11 Lucid.

I open the native macOS Emacs normally by double clicking the icon.  I open the Free BSD version by ssh’ing over to the BSD machine, doing `emacs —batch` and then connecting to it via `emacsclient -n -c -e nil -u`.  I end up with a macOS Emacs and a Free BSD Emacs being displayed on my laptop.

I’ve been playing with frames, displays, and monitors and I more or less understand everything I think but I think there is a bug and I have one question.

When I do `(display-monitor-attributes-list)` from the macOS Emacs with the 2nd monitor connected I get this:

```
(
 (
  (geometry 0  0 1920 1080)
  (workarea 0 25 1920 1055)
  (mm-size 478 268)
  (frames #<frame *scratch* 0x14489a030>)
  (source . "NS")
 )
 (
  (geometry 192 1080 1512 982)
  (workarea 192 1080 1512 950)
  (mm-size 301 195)
  (frames)
  (source . "NS")
 )
)
```

The top is the monitor and the bottom is the laptop’s display.  Notice that ‘name is not present.

If I do `(display-pixel-height)` with the monitor attached, I get 2062 which is the sum of the two heights.  If I detach the monitor, I get 982 which is the height of the laptop’s display.  All good.

However, the X11 version does not do this.  I always get 2025.  The output from `(display-monitor-attributes-list)` changes.  With the monitor attached, there are two entries roughly like the one above and when the monitor is not attached, the output is a single entry.

The 2025 appears to be the value when the first window is opened perhaps?  It is the same value as the sum of the heights when the monitor is attached.  And it appears that it is not getting updated when the monitor is detached.  Is this a bug?  If so, I can report it but thought I would check here first.  (I also can’t follow how x_display_pixel_height works but that’s a detail.)

My question pertains to the name of the monitors.  Can I somehow give the monitors names that will last for the life of Emacs?

I hope my descriptions make sense to others.
Thank you for your time,
Perry


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: (x-display-pixel-height)
  2022-05-18 22:56 (x-display-pixel-height) Perry Smith
@ 2022-05-19  1:05 ` Po Lu
  2022-05-19 14:52   ` (x-display-pixel-height) Perry Smith
  0 siblings, 1 reply; 14+ messages in thread
From: Po Lu @ 2022-05-19  1:05 UTC (permalink / raw)
  To: Perry Smith; +Cc: emacs-devel

Perry Smith <pedz@easesoftware.com> writes:

> However, the X11 version does not do this.  I always get 2025.  The
> output from `(display-monitor-attributes-list)` changes.  With the
> monitor attached, there are two entries roughly like the one above and
> when the monitor is not attached, the output is a single entry.
>
> The 2025 appears to be the value when the first window is opened
> perhaps?  It is the same value as the sum of the heights when the
> monitor is attached.  And it appears that it is not getting updated
> when the monitor is detached.  Is this a bug?  If so, I can report it
> but thought I would check here first.  (I also can’t follow how
> x_display_pixel_height works but that’s a detail.)

Xlib determines the height of the core protocol screen statically upon
connecting to an X server.  It cannot change as monitors are hotplugged.

In X, there are about 3 or 4 different ways to fetch screen and/or
monitor dimensions.  Each of them behave differently.

`x-display-pixel-height' uses the core HeightOfScreen, while
`display-monitor-attributes-list' defaults to using the RandR extension,
which can change dynamically as the screen dimensions are updated.
(That will be fixed in Emacs 29.)

As for why you always get 2025 instead of 2062, I think your X server is
only including the "workarea" of the macOS display in its screen
dimensions.

In general, every X server that doesn't run on actual hardware or a
Wayland compositor reports screen dimensions and input devices
incorrectly.  That cannot be helped.

> My question pertains to the name of the monitors.  Can I somehow give
> the monitors names that will last for the life of Emacs?

No, unfortunately not.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: (x-display-pixel-height)
  2022-05-19  1:05 ` (x-display-pixel-height) Po Lu
@ 2022-05-19 14:52   ` Perry Smith
  2022-05-20  1:04     ` (x-display-pixel-height) Po Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Perry Smith @ 2022-05-19 14:52 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 160 bytes --]

Is there a hook that is called when a monitor is added or removed?  i.e. a hook called when the results from `display-monitor-attributes-list` have changed?


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: (x-display-pixel-height)
  2022-05-19 14:52   ` (x-display-pixel-height) Perry Smith
@ 2022-05-20  1:04     ` Po Lu
  2022-05-20 16:43       ` ***SPAM*** (x-display-pixel-height) Perry Smith
  0 siblings, 1 reply; 14+ messages in thread
From: Po Lu @ 2022-05-20  1:04 UTC (permalink / raw)
  To: Perry Smith; +Cc: emacs-devel

Perry Smith <pedz@easesoftware.com> writes:

> Is there a hook that is called when a monitor is added or removed?
> i.e. a hook called when the results from
> `display-monitor-attributes-list` have changed?

No, not presently.  But I'm open to implementing that feature if there's
a valid usecase.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-20  1:04     ` (x-display-pixel-height) Po Lu
@ 2022-05-20 16:43       ` Perry Smith
  2022-05-21  1:33         ` Po Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Perry Smith @ 2022-05-20 16:43 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

I honestly don’t know if my use case is valid.

I tend to work with just one frame — tend, but not always.  And I often move from my desk where the monitor is to a lounge chair.  When I do, I have to resize my screen.  (Insert reference to Amber Heard.)  I wrote something that will center the frame in the largest monitor, make it half the width, and full height.  I was just looking for a way to automatically trigger that when the monitor is plugged in and out.  But… honestly, how many folks are going to want that?

Totally up to you.  And if I can help, please ask but I was a device driver type person.  Never played much up in application space.
Perry

> On May 19, 2022, at 20:04, Po Lu <luangruo@yahoo.com> wrote:
> 
> Perry Smith <pedz@easesoftware.com> writes:
> 
>> Is there a hook that is called when a monitor is added or removed?
>> i.e. a hook called when the results from
>> `display-monitor-attributes-list` have changed?
> 
> No, not presently.  But I'm open to implementing that feature if there's
> a valid usecase.


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-20 16:43       ` ***SPAM*** (x-display-pixel-height) Perry Smith
@ 2022-05-21  1:33         ` Po Lu
  2022-05-21  3:19           ` Po Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Po Lu @ 2022-05-21  1:33 UTC (permalink / raw)
  To: Perry Smith; +Cc: emacs-devel

Perry Smith <pedz@easesoftware.com> writes:

> I tend to work with just one frame — tend, but not always.  And I
> often move from my desk where the monitor is to a lounge chair.  When
> I do, I have to resize my screen.  (Insert reference to Amber Heard.)
> I wrote something that will center the frame in the largest monitor,
> make it half the width, and full height.  I was just looking for a way
> to automatically trigger that when the monitor is plugged in and out.
> But… honestly, how many folks are going to want that?

Sounds reasonable, I'll try to work on it.  Thanks.




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-21  1:33         ` Po Lu
@ 2022-05-21  3:19           ` Po Lu
  2022-05-21  7:56             ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Po Lu @ 2022-05-21  3:19 UTC (permalink / raw)
  To: Perry Smith; +Cc: emacs-devel

Po Lu <luangruo@yahoo.com> writes:

> Sounds reasonable, I'll try to work on it.  Thanks.

What you want should now be `display-monitors-changed-functions' in
Emacs 29.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-21  3:19           ` Po Lu
@ 2022-05-21  7:56             ` Eli Zaretskii
  2022-05-21  8:24               ` Po Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2022-05-21  7:56 UTC (permalink / raw)
  To: Po Lu; +Cc: pedz, emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Sat, 21 May 2022 11:19:18 +0800
> 
> Po Lu <luangruo@yahoo.com> writes:
> 
> > Sounds reasonable, I'll try to work on it.  Thanks.
> 
> What you want should now be `display-monitors-changed-functions' in
> Emacs 29.

Thanks.

However, the documentation of this hook IMO falls short of being
useful to Lisp programs:

  +@defvar display-monitors-changed-functions
  +This variable is an abnormal hook run when the monitor configuration
  +changes, which can happen if a monitor is rotated, moved, added or
  +removed from a multiple-monitor setup, if the primary monitor changes,
  +or if the resolution of a monitor changes.  It is called with a single
  +argument consisting of the terminal on which the monitor configuration
  +changed.
  +@end defvar

This doesn't give any hints for how should a Lisp program get the
information about the monitor-configuration changes that triggered the
hook call, given just the terminal name.  Without knowing how to
access that information, this hook is not very useful.

I also notice that this hook was implemented for all the supported GUI
backends except w32, which is unfortunate and undocumented.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-21  7:56             ` Eli Zaretskii
@ 2022-05-21  8:24               ` Po Lu
  2022-05-21  8:33                 ` Eli Zaretskii
  2022-05-22  1:35                 ` Po Lu
  0 siblings, 2 replies; 14+ messages in thread
From: Po Lu @ 2022-05-21  8:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

[Removed Perry since his address bounces.]

Eli Zaretskii <eliz@gnu.org> writes:

> Thanks.
>
> However, the documentation of this hook IMO falls short of being
> useful to Lisp programs:
>
>   +@defvar display-monitors-changed-functions
>   +This variable is an abnormal hook run when the monitor configuration
>   +changes, which can happen if a monitor is rotated, moved, added or
>   +removed from a multiple-monitor setup, if the primary monitor changes,
>   +or if the resolution of a monitor changes.  It is called with a single
>   +argument consisting of the terminal on which the monitor configuration
>   +changed.
>   +@end defvar
>
> This doesn't give any hints for how should a Lisp program get the
> information about the monitor-configuration changes that triggered the
> hook call, given just the terminal name.  Without knowing how to
> access that information, this hook is not very useful.

That information isn't available in sufficient detail inside the events
that we get from the window system.  The idea is that programs will call
`display-monitor-attributes-list' to retrieve the new monitor
configuration, which is always available after the hook is run.

How about this?

@cindex monitor change functions
@defvar display-monitors-changed-functions
This variable is an abnormal hook run when the monitor configuration
changes, which can happen if a monitor is rotated, moved, added or
removed from a multiple-monitor setup, if the primary monitor changes,
or if the resolution of a monitor changes.  It is called with a single
argument consisting of the terminal on which the monitor configuration
changed.  Programs should call @code{display-monitor-attributes-list}
with the terminal as the argument to retrieve the changed monitor
configuration inside this hook.
@end defvar

> I also notice that this hook was implemented for all the supported GUI
> backends except w32, which is unfortunate and undocumented.

I plan to try implementing it there in the coming days.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-21  8:24               ` Po Lu
@ 2022-05-21  8:33                 ` Eli Zaretskii
  2022-05-21  8:39                   ` Po Lu
  2022-05-22  1:35                 ` Po Lu
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2022-05-21  8:33 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Sat, 21 May 2022 16:24:03 +0800
> 
> > This doesn't give any hints for how should a Lisp program get the
> > information about the monitor-configuration changes that triggered the
> > hook call, given just the terminal name.  Without knowing how to
> > access that information, this hook is not very useful.
> 
> That information isn't available in sufficient detail inside the events
> that we get from the window system.  The idea is that programs will call
> `display-monitor-attributes-list' to retrieve the new monitor
> configuration, which is always available after the hook is run.
> 
> How about this?
> 
> @cindex monitor change functions
> @defvar display-monitors-changed-functions
> This variable is an abnormal hook run when the monitor configuration
> changes, which can happen if a monitor is rotated, moved, added or
> removed from a multiple-monitor setup, if the primary monitor changes,
> or if the resolution of a monitor changes.  It is called with a single
> argument consisting of the terminal on which the monitor configuration
> changed.  Programs should call @code{display-monitor-attributes-list}
> with the terminal as the argument to retrieve the changed monitor
> configuration inside this hook.
> @end defvar

This is okay, but please say "to retrieve the new configuration on
that terminal" instead of a more vague "to retrieve the changed
monitor configuration".

> > I also notice that this hook was implemented for all the supported GUI
> > backends except w32, which is unfortunate and undocumented.
> 
> I plan to try implementing it there in the coming days.

TIA.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-21  8:33                 ` Eli Zaretskii
@ 2022-05-21  8:39                   ` Po Lu
  0 siblings, 0 replies; 14+ messages in thread
From: Po Lu @ 2022-05-21  8:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> This is okay, but please say "to retrieve the new configuration on
> that terminal" instead of a more vague "to retrieve the changed
> monitor configuration".

Sure, thanks.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-21  8:24               ` Po Lu
  2022-05-21  8:33                 ` Eli Zaretskii
@ 2022-05-22  1:35                 ` Po Lu
  2022-05-22  5:57                   ` Eli Zaretskii
  1 sibling, 1 reply; 14+ messages in thread
From: Po Lu @ 2022-05-22  1:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Po Lu <luangruo@yahoo.com> writes:

>> I also notice that this hook was implemented for all the supported GUI
>> backends except w32, which is unfortunate and undocumented.
>
> I plan to try implementing it there in the coming days.

Hmm, I have a few questions: is it safe to assume the WM_DISPLAYCHANGE
message will always be defined in the Windows headers Emacs is built
with, and does it exist on Windows 9x?

Thanks.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-22  1:35                 ` Po Lu
@ 2022-05-22  5:57                   ` Eli Zaretskii
  2022-05-22  6:18                     ` Po Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2022-05-22  5:57 UTC (permalink / raw)
  To: Po Lu; +Cc: emacs-devel

> From: Po Lu <luangruo@yahoo.com>
> Cc: emacs-devel@gnu.org
> Date: Sun, 22 May 2022 09:35:27 +0800
> 
> Hmm, I have a few questions: is it safe to assume the WM_DISPLAYCHANGE
> message will always be defined in the Windows headers Emacs is built
> with, and does it exist on Windows 9x?

Yes, see

  http://winapi.freetechsecrets.com/win32/WIN32WMDISPLAYCHANGE.htm

(which is IME an invaluable resource for finding information about API
support in old versions of Windows that Microsoft don't want us to
know about).

Of course, Windows 9X didn't support multiple monitors or PnP
monitors, so only resolution changes are relevant to those versions.
But I think w32-display-monitor-attributes-list already handles the
old versions gracefully.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: ***SPAM***  Re: (x-display-pixel-height)
  2022-05-22  5:57                   ` Eli Zaretskii
@ 2022-05-22  6:18                     ` Po Lu
  0 siblings, 0 replies; 14+ messages in thread
From: Po Lu @ 2022-05-22  6:18 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Yes, see
>
>   http://winapi.freetechsecrets.com/win32/WIN32WMDISPLAYCHANGE.htm
>
> (which is IME an invaluable resource for finding information about API
> support in old versions of Windows that Microsoft don't want us to
> know about).
>
> Of course, Windows 9X didn't support multiple monitors or PnP
> monitors, so only resolution changes are relevant to those versions.
> But I think w32-display-monitor-attributes-list already handles the
> old versions gracefully.

Thanks.



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-05-22  6:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 22:56 (x-display-pixel-height) Perry Smith
2022-05-19  1:05 ` (x-display-pixel-height) Po Lu
2022-05-19 14:52   ` (x-display-pixel-height) Perry Smith
2022-05-20  1:04     ` (x-display-pixel-height) Po Lu
2022-05-20 16:43       ` ***SPAM*** (x-display-pixel-height) Perry Smith
2022-05-21  1:33         ` Po Lu
2022-05-21  3:19           ` Po Lu
2022-05-21  7:56             ` Eli Zaretskii
2022-05-21  8:24               ` Po Lu
2022-05-21  8:33                 ` Eli Zaretskii
2022-05-21  8:39                   ` Po Lu
2022-05-22  1:35                 ` Po Lu
2022-05-22  5:57                   ` Eli Zaretskii
2022-05-22  6:18                     ` Po Lu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).