Subject: bug#38452: [Pascal Lambrechts] Re: bug#38452: 26.3; set-frame-position is slightly drifted

From: Pascal Lambrechts <[email-masked]>
Date: Tue, 3 Dec 2019 15:04:51 +0000

-- 
Pascal Lambrechts  --  UCLouvain (SST/SC/MATH IRMP)
building: Marc De Hemptinne (Louvain-la-Neuve) - Local: B 430
phone: +32 (0)104x73161 
IRMP bte L7.01.02 // Chemin du Cyclotron 2 //  1348 Louvain-la-Neuve // Belgium

Subject: Re: bug#38452: 26.3; set-frame-position is slightly drifted
From: Pascal Lambrechts <[email-masked]>
To: martin rudalics <[email-masked]>
Date: Tue, 03 Dec 2019 15:08:23 +0100

Martin,

I answer some of your quesions inside your mail.
Also at the end of the mail I add a copy of a scratch buffer on which I did
more experiments (with one or two displays).
As you can read in this scratch the behaviour is even more mysterious
now. Indeed if I set the parameters and read them back by
frame-parameter both evaluated in a enclosing progn then I get the
expected values. But if I reread right after the parameters I get 
different values !?

martin rudalics <[email-masked]> writes:
> Pascal, thanks for replying.  I quote your mail in full below so it
> appears that way on the bug tracker.  Please always use "reply to all"
> when answering, so none of your mails get lost.
>
>  > When I does
>  > (set-frame-position nil 0 0)
>  > the frame jump to the left topmost point of the avalaible screen not
>  > counting the dock (which on my gnome-3 desktop is on the left side) neither the
>  > main menu line.
>  > If I repeat that command the frame does not move.
>  >
>  > But in that situation I get the evaluations:
>  > (frame-parameter nil 'left) ==> 45
>  > (frame-parameter nil 'top)  ==>  19
>  >
>  > Now if I evaluate (set-frame-position nil 45 19)
>  > the frame does not move (comparing with putting the frame at (0,0))
>  > and the parameters left and top keep unchanged values 45 and 19
>  >
>  > If now I evaluate:
>  >
>  > (set-frame-position nil 100 60)
>  > (frame-parameter nil 'left)
>  > (frame-parameter nil 'top)
>  > I get the values 90 and 52 for left and top.
>  >
>  > If reconfigure gnome so that the dock  appears on the bottom of
>  > my screen instead of the left edge, then
>  > (set-frame-position nil 0 0)
>  > moves the frame on the leftmost position of the screen and
>  > (frame-parameter nil 'left) ==> (+ -10)
>
>  From this I conclude that the dock should be responsible for the
> behavior you see.  Which window manager do you use?  What do you get
> when you evaluate (display-monitor-attributes-list) in Emacs?
Here are the values of 
(display-monitor-attributes-list)  
when the dock is on the left or the bottom of the screen (the workarea
are distinct)

pl-dock-left’s value is
(((name . "eDP-1")
  (geometry 0 0 1920 1080)
  (workarea 55 27 1865 1053)
  (mm-size 309 174)
  (frames #<frame  *Minibuf-2* 0x4e723c0> #<frame *unsent mail to martin rudalics* 0x5289930>)
  (source . "Gdk")))

pl-dock-bottom’s value is
(((name . "eDP-1")
  (geometry 0 0 1920 1080)
  (workarea 0 27 1920 1000)
  (mm-size 309 174)
  (frames #<frame  *Minibuf-2* 0x4e723c0> #<frame *unsent mail to martin rudalics* 0x5289930>)
  (source . "Gdk")))

>Are > there differences in the workarea values when you evaluate that
> expression with the dock on the left and at the bottom?
Indeed see above
>
> Also you say that
>
> (set-frame-position nil 0 0)
>
> and
>
> (set-frame-position nil 45 19)
>
> both put the frame at the same position on the screen and in both
> cases the following evaluations result:
>
> (frame-parameter nil 'left) ==> 45
> (frame-parameter nil 'top)  ==>  19
>
> Is my reading of your text right?  If so, then the "problems" seem to
> start when the X-value is somewhere between 45 and 100 and the Y-value
> between 19 and 60.  Right?
Yes I did some experiment in the scratch file.
In the first configuration (my laptop screen as a unique scrren) it
seems that when the frame is at the top left corner the parameters
take values (L=45,T=19) (which probably correspond to the width of the
dock and height of the menu line).
If I set-frame-position at (x,y) with 0<=x<=55 and 0<=y<=27 then the
frame does not move and the values are reset to (45,19).
If I set-frame-position at (60,30) then the frame moved a little bit and
the parameters evaluate to (50,22).
>
> Since the behavior apparently changes when you move the dock to the
> bottom, the X-positioning seems clearly related to the position of the
> dock.  Would the Y-positioning then be related to the presence of the
> main menu line (presumably on the bottom)?  The one thing that
> stupefies me then in either case is why the deviations are 10 and 8
> pixels only.  I presume that both, your dock and the menu line, are
> wider.

Yes the dock and menu line are certainly wider than 10 et 8 pixels.
> Thanks, martin

Here is a scratch file on which I did some experiment commented.
Th function pl-lt is defined to easily show the values of the parameters
left/top of the frame:

========================== SCRACTCH INTERACTIVE LISP FILE WITH EXPERMINTS ========================================
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with <open> and enter text in its buffer.

;; Experiments with set-frame-position and the result values of the parameters left and top of the frame
;; Each parenthesis sexp has been evaluated with C-j = eval-print-last-sexp
(defun pl-lt ()
  "Returns a string giving the left/top positions of the current frame"
  (concat " LEFT="
	  (prin1-to-string (frame-parameter nil 'left))
	  "  TOP="
	  (prin1-to-string (frame-parameter nil 'top))))

;; First experiments with the laptop as only display and  the gnome-3 dock on the left:
(display-monitor-attributes-list)
(((name . "eDP-1") (geometry 0 0 1920 1080) (workarea 55 27 1865 1053) (mm-size 309 174) (frames #<frame *scratch* 0x4e723c0> #<frame *unsent mail to martin rudalics* 0x5289930>) (source . "Gdk")))

(set-frame-position nil 0 0)
t
;; the frame is immediately below the menu line and on the immediate right of  the left dock
(pl-lt)
" LEFT=45  TOP=19"
(progn (set-frame-position nil 0 0) (pl-lt))
" LEFT=0  TOP=0"
 (pl-lt)
" LEFT=45  TOP=19"
(set-frame-position nil 45 19)
t
;; this did not move the frame: still at left corner but not overlaping the dock or menu line
(pl-lt)
" LEFT=45  TOP=19"
(progn (set-frame-position nil 45 19) (pl-lt))
" LEFT=45  TOP=19"
(pl-lt)
" LEFT=45  TOP=19"
(progn (set-frame-position nil 50 25) (pl-lt))
" LEFT=50  TOP=25"
;; this did not move the frame 
(pl-lt)
" LEFT=45  TOP=19"
;; the parameters changed between the (pl-lt) inside the progn and after !!!
(progn (set-frame-position nil 55 27) (pl-lt))
" LEFT=55  TOP=27"
;; this did not move the frame 
(pl-lt)
" LEFT=45  TOP=19"
(progn (set-frame-position nil 60 30) (pl-lt))
" LEFT=60  TOP=30"
;; this moved very slight the frame away from the left-top corner
(pl-lt)
" LEFT=50  TOP=22"

(set-frame-position nil 400 100)
t
;; this moved the frame sowewhere in the middle of the screen
(pl-lt)
" LEFT=390  TOP=92"
(progn (set-frame-position nil 390 92) (pl-lt))
" LEFT=390  TOP=92"
;; this moved a bit the frame towars the top left corner
(pl-lt)
" LEFT=380  TOP=84"

;; ---------------------------
;; Second experiments with an external screen as single display
(display-monitor-attributes-list)
(((name . "DP-1-2") (geometry 0 0 1920 1080) (workarea 55 27 1865 1053) (mm-size 598 336) (frames #<frame *scratch* 0x4e723c0> #<frame *unsent mail to martin rudalics* 0x5289930>) (source . "Gdk")))

(set-frame-position nil 0 0)
;; the frame is immediately below the menu line and on the immediate right of  the left dock
t
(pl-lt)
" LEFT=45  TOP=19"
(progn (set-frame-position nil 0 0) (pl-lt))
" LEFT=0  TOP=0"
(pl-lt)

;; Third experiment with a double display: internal display of laptop + external display
;; The external display is set as the 'primary' display and is supposed to be on the right
;; of the laptop display. So the menu bar and dock are only on the external display
(display-monitor-attributes-list)
(((name . "DP-1-2") (geometry 1920 0 1920 1080) (workarea 1920 27 1920 1053) (mm-size 598 336) (frames #<frame *scratch* 0x4e723c0> #<frame *unsent mail to martin rudalics* 0x5289930>) (source . "Gdk")) ((name . "eDP-1") (geometry 0 0 1920 1080) (workarea 0 0 1920 1080) (mm-size 309 174) (frames) (source . "Gdk")))
(set-frame-position nil 0 0)
t
;; the frame is now in the left-top corner of the laptoop screen (no menu neither dock here)
(pl-lt)
" LEFT=(+ -10)  TOP=(+ -8)"
(progn (set-frame-position nil 0 0) (pl-lt))
" LEFT=0  TOP=0"
(pl-lt)
" LEFT=(+ -10)  TOP=(+ -8)"
(progn (set-frame-position nil (+ -10) (+ -8)) (pl-lt))
" LEFT=2842  TOP=288"
;; the previous evaluation has moved the frame on the external display close to the right corner
(pl-lt)
" LEFT=2832  TOP=280"
(progn (set-frame-position nil 2832 280) (pl-lt))
" LEFT=2832  TOP=280"
;; the previous sexpevaluation has moved the frame slighly to the left and top 

-- 
Pascal Lambrechts  --  UCLouvain (SST/SC/MATH IRMP)
building: Marc De Hemptinne (Louvain-la-Neuve) - Local: B 430
phone: +32 (0)104x73161 
IRMP bte L7.01.02 // Chemin du Cyclotron 2 //  1348 Louvain-la-Neuve // Belgium