Subject: Re: bug#34680: Display monitor frames not warmed up

From: Juri Linkov <[email-masked]>
Date: Mon, 04 Mar 2019 23:03:31 +0200

>> I guess calling the function ‘message’ before calling
>> ‘display-monitor-attributes-list’ performs some redisplay that adds
>> the frame to the list of frames in ‘display-monitor-attributes-list’.
>
> It also fixes the issue when using any of the following
> ‘redisplay’, ‘redraw-display’, ‘redraw-frame’, or just
> ‘display-monitor-attributes-list’ before calling
> ‘frame-monitor-attributes’ for the first time.
>
> Just calling ‘display-monitor-attributes-list’ somehow “registers” the
> frame in the list of frames, so the next call of ‘display-monitor-attributes-list’
> returns the attribute ‘frames’ containing the frame.

I can't explain this, but this is the minimal patch that fixes my
problem.  This dry run by calling gdk_display_get_monitor_at_window
ignores its first wrong return value, so its subsequent calls return
correct values.

diff --git a/src/xfns.c b/src/xfns.c
index a627b7e19e..9096595625 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -4943,6 +4943,7 @@ Internal use only, use `display-monitor-attributes-list' instead.  */)
 	  && !FRAME_TOOLTIP_P (f))
 	{
 	  GdkWindow *gwin = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
+	  gdk_display_get_monitor_at_window (gdpy, gwin);
 
 #if GTK_CHECK_VERSION (3, 22, 0)
           for (i = 0; i < n_monitors; i++)