set-frame-position
在单个屏幕没有任何问题,但是双屏幕,就会有 x < 0 这种情况存在,这会使得 snails 的弹出框位置不在预期上。
+------------------------------+ +-----------------------------+
| | | |
| | | |
| Screen 2 | | Screen 1 |
| | | |
| | | |
| | | |
+------------------------------+ +-----------------------------+
x < 0 x > 0
这是 set-frame-position
的文档说明,明确指出了 X
and Y
定义的问题。
/* Set position of FRAME to (X, Y). FRAME must be a live frame and defaults to the selected one. X and Y, if positive, specify the coordinate of the left and top edge of FRAME’s outer frame in pixels relative to an origin (0, 0) of FRAME’s display. If any of X or Y is negative, it specifies the coordinates of the right or bottom edge of the outer frame of FRAME relative to the right or bottom edge of FRAME’s display. */
我目前 tweak 了 snails 的 snails-create-frame
函数。
(frame-x (if (< x 0) (- x (- (/ (- width frame-width) 2)) (/ 1366 2))
(+ x (/ (- width frame-width) 2))))
1366 是我 Screen 1 屏幕的像素宽度 。
目前,还是不能完美解决,但是至少在我 99% 的情况下,让 snails 的弹出位置处在当前 frame 的中央。
和大家分享一下,如果有更好的解决办法,希望大家指出。