all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Is there a way to control where frames get created?
@ 2018-09-29 22:37 Perry E. Metzger
  2018-09-30  1:37 ` Drew Adams
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Perry E. Metzger @ 2018-09-29 22:37 UTC (permalink / raw)
  To: emacs-devel

I'd like to rig things up so that make-frame-command creates its new
frame adjacent to the existing frame if that's geometrically
possible on the GUI display. To do that, I'd need to both be able to
find out where the existing frame is, and to tell make-frame-command
where to create the new frame.

Are there any hooks that make this possible? Any advice on how I might
go about doing it?

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* RE: Is there a way to control where frames get created?
  2018-09-29 22:37 Is there a way to control where frames get created? Perry E. Metzger
@ 2018-09-30  1:37 ` Drew Adams
  2018-09-30  7:57 ` martin rudalics
  2018-09-30 11:58 ` Michael Heerdegen
  2 siblings, 0 replies; 16+ messages in thread
From: Drew Adams @ 2018-09-30  1:37 UTC (permalink / raw)
  To: Perry E. Metzger, emacs-devel

> I'd like to rig things up so that make-frame-command creates its new
> frame adjacent to the existing frame if that's geometrically
> possible on the GUI display. To do that, I'd need to both be able to
> find out where the existing frame is, and to tell make-frame-command
> where to create the new frame.
> 
> Are there any hooks that make this possible? Any advice on how I might
> go about doing it?

Not sure exactly what you're asking. Adjacent in what direction? What do you mean by "geometrically possible" - do you mean if the display is wide enough (if adjacent horizontally) or tall enough (if adjacent vertically)? Do you allow the existing frame to be resized at all  - e.g. to tile it and the new frame together on the display? Do you allow for multiple monitors - and if so, in what configurations?

Anyway, you can get the current frame position and size from its frame parameters, and you can set the new frame position and size based on some transformation of those of the existing frame.

The code in frame-cmds.el might help, either directly (e.g. if tiling) or indirectly. See, for example, command `create-frame-tiled-horizontally':

  Horizontally tile screen with selected frame and a copy.
  The same character size is used for the new frame.

https://www.emacswiki.org/emacs/download/frame-cmds.el



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

* Re: Is there a way to control where frames get created?
  2018-09-29 22:37 Is there a way to control where frames get created? Perry E. Metzger
  2018-09-30  1:37 ` Drew Adams
@ 2018-09-30  7:57 ` martin rudalics
  2018-09-30 12:05   ` Perry E. Metzger
  2018-09-30 14:14   ` Perry E. Metzger
  2018-09-30 11:58 ` Michael Heerdegen
  2 siblings, 2 replies; 16+ messages in thread
From: martin rudalics @ 2018-09-30  7:57 UTC (permalink / raw)
  To: Perry E. Metzger, emacs-devel

 > I'd like to rig things up so that make-frame-command creates its new
 > frame adjacent to the existing frame if that's geometrically
 > possible on the GUI display. To do that, I'd need to both be able to
 > find out where the existing frame is, and to tell make-frame-command
 > where to create the new frame.
 >
 > Are there any hooks that make this possible? Any advice on how I might
 > go about doing it?

To put a frame right on the right of the selected one use

(make-frame `((left . ,(+ (car (frame-position)) (frame-outer-width)))
	      (top . ,(cdr (frame-position)))))

martin



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

* Re: Is there a way to control where frames get created?
  2018-09-29 22:37 Is there a way to control where frames get created? Perry E. Metzger
  2018-09-30  1:37 ` Drew Adams
  2018-09-30  7:57 ` martin rudalics
@ 2018-09-30 11:58 ` Michael Heerdegen
  2 siblings, 0 replies; 16+ messages in thread
From: Michael Heerdegen @ 2018-09-30 11:58 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

"Perry E. Metzger" <perry@piermont.com> writes:

> I'd like to rig things up so that make-frame-command creates its new
> frame adjacent to the existing frame if that's geometrically
> possible on the GUI display. To do that, I'd need to both be able to
> find out where the existing frame is, and to tell make-frame-command
> where to create the new frame.

I want something similar if I understand you correctly: I want that all
frames appear slightly shifted horizontally.  I use
'after-make-frame-functions' to implement this:

#+begin_src emacs-lisp
(require 'cl-lib)

(defun my-reposition-frame-after-create (frame)
  (when window-system
    (if  (> (frame-pixel-width frame) (display-pixel-width))
        (set-frame-parameter nil 'fullscreen 'maximized)
      (let* ((frames (delq frame (filtered-frame-list (lambda (f) (eq t (frame-visible-p f))))))
             (xs (cl-remove-if (lambda (val) (not (integerp val)))
                               (mapcar (lambda (f) (frame-parameter f 'left)) frames)))
             (new-x 0))
        (while (member new-x xs)
          (cl-incf new-x 20))
        (set-frame-parameter frame 'left new-x)
        (set-frame-parameter frame 'user-position t)))))

(add-hook 'after-make-frame-functions #'my-reposition-frame-after-create)
#+end_src

It's a hack but got enough for me.  I have some more related stuff,
e.g. to reorder frames to fill the gap of a deleted frame.


Michael.



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

* Re: Is there a way to control where frames get created?
  2018-09-30  7:57 ` martin rudalics
@ 2018-09-30 12:05   ` Perry E. Metzger
  2018-09-30 12:22     ` martin rudalics
  2018-09-30 14:14   ` Perry E. Metzger
  1 sibling, 1 reply; 16+ messages in thread
From: Perry E. Metzger @ 2018-09-30 12:05 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

On Sun, 30 Sep 2018 09:57:48 +0200 martin rudalics <rudalics@gmx.at>
wrote:
>  > I'd like to rig things up so that make-frame-command creates its
>  > new frame adjacent to the existing frame if that's geometrically
>  > possible on the GUI display. To do that, I'd need to both be
>  > able to find out where the existing frame is, and to tell
>  > make-frame-command where to create the new frame.
>  >
>  > Are there any hooks that make this possible? Any advice on how I
>  > might go about doing it?  
> 
> To put a frame right on the right of the selected one use
> 
> (make-frame `((left . ,(+ (car (frame-position))
> (frame-outer-width))) (top . ,(cdr (frame-position)))))

Thank you that's precisely what I want to do! I'll try it out.

BTW, do you know what this does if there isn't sufficient room to the
right?

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: Is there a way to control where frames get created?
  2018-09-30 12:05   ` Perry E. Metzger
@ 2018-09-30 12:22     ` martin rudalics
  0 siblings, 0 replies; 16+ messages in thread
From: martin rudalics @ 2018-09-30 12:22 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

 > BTW, do you know what this does if there isn't sufficient room to the
 > right?

You should take care of that ideally using the workarea value returned
by 'display-monitor-attributes-list'.  Otherwise, you risk that many
window managers will refuse to place the new window as asked for if it
does not entirely fit into the workarea.

martin



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

* Re: Is there a way to control where frames get created?
  2018-09-30  7:57 ` martin rudalics
  2018-09-30 12:05   ` Perry E. Metzger
@ 2018-09-30 14:14   ` Perry E. Metzger
  2018-09-30 14:41     ` Perry E. Metzger
  1 sibling, 1 reply; 16+ messages in thread
From: Perry E. Metzger @ 2018-09-30 14:14 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

On Sun, 30 Sep 2018 09:57:48 +0200 martin rudalics <rudalics@gmx.at>
wrote:
>  > I'd like to rig things up so that make-frame-command creates its
>  > new frame adjacent to the existing frame if that's geometrically
>  > possible on the GUI display. To do that, I'd need to both be
>  > able to find out where the existing frame is, and to tell
>  > make-frame-command where to create the new frame.
>  >
>  > Are there any hooks that make this possible? Any advice on how I
>  > might go about doing it?  
> 
> To put a frame right on the right of the selected one use
> 
> (make-frame `((left . ,(+ (car (frame-position))
> (frame-outer-width))) (top . ,(cdr (frame-position)))))

FYI, this turns out to be absolutely perfect. Thank you for that code
snippet.

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: Is there a way to control where frames get created?
  2018-09-30 14:14   ` Perry E. Metzger
@ 2018-09-30 14:41     ` Perry E. Metzger
  2018-09-30 16:20       ` Stefan Monnier
  2018-09-30 17:47       ` martin rudalics
  0 siblings, 2 replies; 16+ messages in thread
From: Perry E. Metzger @ 2018-09-30 14:41 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

On Sun, 30 Sep 2018 10:14:35 -0400 "Perry E. Metzger"
<perry@piermont.com> wrote:
> > To put a frame right on the right of the selected one use
> >
> > (make-frame `((left . ,(+ (car (frame-position))
> > (frame-outer-width))) (top . ,(cdr (frame-position)))))
>
> FYI, this turns out to be absolutely perfect. Thank you for that
> code snippet.

Actually, it is _almost_ perfect. For some odd reason, the new window
ends up a few pixels lower than the old. I can fix this with some
subtraction but I'm puzzled why setting top to (cdr (frame-position))
isn't quite doing the right thing.

-- 
Perry E. Metzger		perry@piermont.com



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

* Re: Is there a way to control where frames get created?
  2018-09-30 14:41     ` Perry E. Metzger
@ 2018-09-30 16:20       ` Stefan Monnier
  2018-09-30 17:48         ` martin rudalics
  2018-09-30 17:47       ` martin rudalics
  1 sibling, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2018-09-30 16:20 UTC (permalink / raw)
  To: emacs-devel

> Actually, it is _almost_ perfect. For some odd reason, the new window
> ends up a few pixels lower than the old. I can fix this with some
> subtraction but I'm puzzled why setting top to (cdr (frame-position))
> isn't quite doing the right thing.

Probably the difference between the position of the inner and the
outer (decoration) window.


        Stefan




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

* Re: Is there a way to control where frames get created?
  2018-09-30 14:41     ` Perry E. Metzger
  2018-09-30 16:20       ` Stefan Monnier
@ 2018-09-30 17:47       ` martin rudalics
  2018-09-30 18:35         ` Perry E. Metzger
  1 sibling, 1 reply; 16+ messages in thread
From: martin rudalics @ 2018-09-30 17:47 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

 > Actually, it is _almost_ perfect. For some odd reason, the new window
 > ends up a few pixels lower than the old. I can fix this with some
 > subtraction but I'm puzzled why setting top to (cdr (frame-position))
 > isn't quite doing the right thing.

What are the values returned by 'frame-geometry' for the old and the
new frame?  Which window manager do you use?  Which toolkit?

martin




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

* Re: Is there a way to control where frames get created?
  2018-09-30 16:20       ` Stefan Monnier
@ 2018-09-30 17:48         ` martin rudalics
  2018-09-30 18:07           ` Perry E. Metzger
  0 siblings, 1 reply; 16+ messages in thread
From: martin rudalics @ 2018-09-30 17:48 UTC (permalink / raw)
  To: Stefan Monnier, emacs-devel

 > Probably the difference between the position of the inner and the
 > outer (decoration) window.

This would be the first time I hear about such a thing.  So far, the
"position" was always the position of the outer frame which includes
the decorations.

martin



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

* Re: Is there a way to control where frames get created?
  2018-09-30 17:48         ` martin rudalics
@ 2018-09-30 18:07           ` Perry E. Metzger
  0 siblings, 0 replies; 16+ messages in thread
From: Perry E. Metzger @ 2018-09-30 18:07 UTC (permalink / raw)
  To: martin rudalics; +Cc: Stefan Monnier, emacs-devel

On Sun, 30 Sep 2018 19:48:10 +0200 martin rudalics <rudalics@gmx.at>
wrote:
>  > Probably the difference between the position of the inner and the
>  > outer (decoration) window.  
> 
> This would be the first time I hear about such a thing.  So far, the
> "position" was always the position of the outer frame which includes
> the decorations.

Also, the difference is only a few pixels, which is smaller than the
difference in size between inner and outer. I find it mysterious.
This is happening on MacOS native if that's any help to anyone,
haven't tried it yet on X11.

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: Is there a way to control where frames get created?
  2018-09-30 17:47       ` martin rudalics
@ 2018-09-30 18:35         ` Perry E. Metzger
  2018-10-01  8:35           ` martin rudalics
  0 siblings, 1 reply; 16+ messages in thread
From: Perry E. Metzger @ 2018-09-30 18:35 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

On Sun, 30 Sep 2018 19:47:53 +0200 martin rudalics <rudalics@gmx.at>
wrote:
>  > Actually, it is _almost_ perfect. For some odd reason, the new
>  > window ends up a few pixels lower than the old. I can fix this
>  > with some subtraction but I'm puzzled why setting top to (cdr
>  > (frame-position)) isn't quite doing the right thing.  
> 
> What are the values returned by 'frame-geometry' for the old and the
> new frame?  Which window manager do you use?  Which toolkit?

This is under MacOS/aqua:

First frame:

((outer-position 0 . 23) (outer-size 675 . 874) (external-border-size
0 . 0) (title-bar-size 0 . 22) (menu-bar-external) (menu-bar-size 0 .
0) (tool-bar-external) (tool-bar-position . top) (tool-bar-size 0 .
0) (internal-border-width . 2))

"New" frame:

((outer-position 690 . 25) (outer-size 675 . 874)
(external-border-size 0 . 0) (title-bar-size 0 . 22)
(menu-bar-external) (menu-bar-size 0 . 0) (tool-bar-external)
(tool-bar-position . top) (tool-bar-size 0 . 0)
(internal-border-width . 2))

So it's two pixels different. Peculiar, eh?

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: Is there a way to control where frames get created?
  2018-09-30 18:35         ` Perry E. Metzger
@ 2018-10-01  8:35           ` martin rudalics
  2018-10-01 11:06             ` Perry E. Metzger
  0 siblings, 1 reply; 16+ messages in thread
From: martin rudalics @ 2018-10-01  8:35 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

 > This is under MacOS/aqua:
 >
 > First frame:
 >
 > ((outer-position 0 . 23) (outer-size 675 . 874) (external-border-size
 > 0 . 0) (title-bar-size 0 . 22) (menu-bar-external) (menu-bar-size 0 .
 > 0) (tool-bar-external) (tool-bar-position . top) (tool-bar-size 0 .
 > 0) (internal-border-width . 2))
 >
 > "New" frame:
 >
 > ((outer-position 690 . 25) (outer-size 675 . 874)
 > (external-border-size 0 . 0) (title-bar-size 0 . 22)
 > (menu-bar-external) (menu-bar-size 0 . 0) (tool-bar-external)
 > (tool-bar-position . top) (tool-bar-size 0 . 0)
 > (internal-border-width . 2))
 >
 > So it's two pixels different. Peculiar, eh?

As you can see, your internal border is two pixels wide.  And Alan just
noted in the thread of Bug#32882:

 > I wonder if it’s the internal border. It’s not properly supported on
 > the NS port for some reason, and therefore should always be the
 > background colour. But it defaults to 2 pixels. Try:
 >
 > (set-frame-parameter nil 'internal-border-width 0)

So please try that before making the new frame.  Unfortunately, in the
follow-up Aaron said it would not change anything and I suppose you
will see the same.  But yours and Aaron's experience could eventually
lead us to where those two pixels come from.

BTW the X-position 690 of your new frame is much larger than I would
expect from 0 + 675.  So this seems even more broken.

martin




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

* Re: Is there a way to control where frames get created?
  2018-10-01  8:35           ` martin rudalics
@ 2018-10-01 11:06             ` Perry E. Metzger
  2018-10-01 15:06               ` martin rudalics
  0 siblings, 1 reply; 16+ messages in thread
From: Perry E. Metzger @ 2018-10-01 11:06 UTC (permalink / raw)
  To: martin rudalics; +Cc: emacs-devel

On Mon, 01 Oct 2018 10:35:16 +0200 martin rudalics <rudalics@gmx.at>
wrote:
>  > This is under MacOS/aqua:
[...]
> As you can see, your internal border is two pixels wide.  And Alan
> just noted in the thread of Bug#32882:
> 
>  > I wonder if it’s the internal border. It’s not properly
>  > supported on the NS port for some reason, and therefore should
>  > always be the background colour. But it defaults to 2 pixels.
>  > Try:
>  >
>  > (set-frame-parameter nil 'internal-border-width 0)  
> 
> So please try that before making the new frame.  Unfortunately, in
> the follow-up Aaron said it would not change anything and I suppose
> you will see the same.  But yours and Aaron's experience could
> eventually lead us to where those two pixels come from.

I'll try that out.

> BTW the X-position 690 of your new frame is much larger than I would
> expect from 0 + 675.  So this seems even more broken.

No, that's fine. I deliberately added 15 pixels there for a couple of
reasons. (I wanted to be able to see if I was obscuring any
terminals, a thin strip of the background is good for this purpose.
It isn't a bug, I did it myself.)

Perry
-- 
Perry E. Metzger		perry@piermont.com



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

* Re: Is there a way to control where frames get created?
  2018-10-01 11:06             ` Perry E. Metzger
@ 2018-10-01 15:06               ` martin rudalics
  0 siblings, 0 replies; 16+ messages in thread
From: martin rudalics @ 2018-10-01 15:06 UTC (permalink / raw)
  To: Perry E. Metzger; +Cc: emacs-devel

 >> BTW the X-position 690 of your new frame is much larger than I would
 >> expect from 0 + 675.  So this seems even more broken.
 >
 > No, that's fine. I deliberately added 15 pixels there for a couple of
 > reasons. (I wanted to be able to see if I was obscuring any
 > terminals, a thin strip of the background is good for this purpose.
 > It isn't a bug, I did it myself.)

A pity somehow, because it means that we don't get any two pixel
symmetry.  If, as a rule, you always subtract two pixels for the top
position of the new window, do you get always exact vertical
alignment?  Even with the old window at top zero?  Or is there some
randomness?

martin



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

end of thread, other threads:[~2018-10-01 15:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-29 22:37 Is there a way to control where frames get created? Perry E. Metzger
2018-09-30  1:37 ` Drew Adams
2018-09-30  7:57 ` martin rudalics
2018-09-30 12:05   ` Perry E. Metzger
2018-09-30 12:22     ` martin rudalics
2018-09-30 14:14   ` Perry E. Metzger
2018-09-30 14:41     ` Perry E. Metzger
2018-09-30 16:20       ` Stefan Monnier
2018-09-30 17:48         ` martin rudalics
2018-09-30 18:07           ` Perry E. Metzger
2018-09-30 17:47       ` martin rudalics
2018-09-30 18:35         ` Perry E. Metzger
2018-10-01  8:35           ` martin rudalics
2018-10-01 11:06             ` Perry E. Metzger
2018-10-01 15:06               ` martin rudalics
2018-09-30 11:58 ` Michael Heerdegen

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.