membrane icon indicating copy to clipboard operation
membrane copied to clipboard

set initial window location to arg or default to 0

Open rgkirch opened this issue 2 years ago • 8 comments

Idk if initial windows have a non-zero default location. If so, then this overrides the default behavior which may be undesirable.

rgkirch avatar Mar 02 '22 23:03 rgkirch

Since I'm also not sure what the default behavior is for all the operating systems Swing supports, then I think we should avoid setting the start location if no initial location is provided.

phronmophobic avatar Mar 02 '22 23:03 phronmophobic

         start-x window-start-x
         start-y window-start-y]
     (.setSize f start-width start-height)
     (when (and start-x start-y) (.setLocation f start-x start-y))

This has the idiosyncrasy that setting window-start-x won't have an effect unless you also set window-start-y. Is that good enough?

rgkirch avatar Mar 02 '22 23:03 rgkirch

This has the idiosyncrasy that setting window-start-x won't have an effect unless you also set window-start-y.

Let's do something like the following:

(when (or window-start-x window-start-y) 
  (assert (and window-start-x window-start-y) "Specifying the window start position must provide both x and y coordinates")
  (.setLocation f window-start-x window-start-y))

phronmophobic avatar Mar 03 '22 06:03 phronmophobic

Yea, I didn't think of that as an option and I like it.

Alternatively, I just realized that the default initial location might be in scope...

         start-x (or window-start-x (.getX f))
         start-y (or window-start-y (.getX f))]
     (.setSize f start-width start-height)
     (.setLocation f start-x start-y)

where f is a JFrame

Does this have any drawbacks?

I feel like I should offer why I'm even interested in supporting a default starting location. I'm recreating the window to load new code and this saves me from moving the window back to where I want it.

rgkirch avatar Mar 03 '22 12:03 rgkirch

Alternatively, I just realized that the default initial location might be in scope...

I was also thinking similarly, but after doing a little more reading, https://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setLocationByPlatform(boolean), it doesn't seem like .getLocation is likely to provide the default platform location. I think our best bet is requiring both the x and y coordinate if either is required. We can always loosen this restriction if we learn otherwise.

phronmophobic avatar Mar 04 '22 21:03 phronmophobic

That sounds good!

rgkirch avatar Mar 10 '22 14:03 rgkirch

Just tried this out. If you pass a window-start-x without a window-start-y, it still shows the window before asserting and throwing the error. The assertion should probably be checked before creating all the panels, listeners, windows, etc.

phronmophobic avatar Mar 24 '22 04:03 phronmophobic

Ah, sorry, I never tested the failure scenario. Good catch!

rgkirch avatar Mar 24 '22 12:03 rgkirch

https://github.com/phronmophobic/membrane/commit/3a706f154d049c214bb0d94ee239c499de91b2c4 Fixed!

phronmophobic avatar Oct 05 '22 01:10 phronmophobic