Skip to content

Add methods to get the position of a window's client area, relative to the desktop#430

Merged
august64 merged 8 commits intorust-windowing:masterfrom
Osspial:get_inner_pos
Apr 17, 2018
Merged

Add methods to get the position of a window's client area, relative to the desktop#430
august64 merged 8 commits intorust-windowing:masterfrom
Osspial:get_inner_pos

Conversation

@Osspial
Copy link
Copy Markdown
Contributor

@Osspial Osspial commented Mar 21, 2018

This differs from the current get_position, in that the current method gets the window's top-left position, including window decorations. This adds a get_inner_position method, which gets the client area's top-left position, not including decorations, relative to the desktop.

@august64
Copy link
Copy Markdown
Member

For me under Xfwm4, get_position and get_inner_position return the same values. However, since that's the result of more fundamental issues with geometry calculation in the X11 backend, I think it's fine for now.

@mitchmindtree
Copy link
Copy Markdown
Contributor

I just tested this on macos 10.12.4 by printing the result of window.get_position() and widow.get_inner_position() within the event loop of the window.rs example and watching the values as I move the window around. Both methods produce the same result which seems to be the "outer" position (top left of the decorations).

Not sure if the get_inner_position mac implementation should be fixed or not before this is merged. Perhaps at least it could be changed to unimplemented!() in the meantime to avoid weird unexpected behaviour issues?

@august64
Copy link
Copy Markdown
Member

august64 commented Apr 7, 2018

Okay, with #438 merged, this works on X11 now.

@mitchmindtree are you sure they were both outer position? I changed the relevant code (and badgered one of my friends into testing it), and it seems that the existing get_position implementation was returning the content area position (judging by both the values returned and the use of contentRectForFrameRect). So, I changed get_inner_position to be identical to the current get_position, and changed get_position to just use the frame rect instead of requesting the content rect.

(Also, it seems that on macOS, set_position sets the content area position. On X11, we set the outer window position, and I'm not sure about the other backends, but that's a concern for a separate issue.)

EDIT: the set_position implementation appears to be informed by that incorrect get_position implementation, and it would be easy to fix: https://github.com/tomaka/winit/blob/591e0d9b8e9f93675c25c70acea846a5d50dae46/src/platform/macos/window.rs#L543-L547

@august64
Copy link
Copy Markdown
Member

august64 commented Apr 8, 2018

Okay, set_position works the same way on Windows as it does on X11, and the docs specify that set_position uses the same coordinates as get_position. I've corrected the implementation of set_position on macOS accordingly.

@august64
Copy link
Copy Markdown
Member

@RobSaunders do you think you could take a look at this?

@august64
Copy link
Copy Markdown
Member

Alright, after getting a chance to test this on macOS hands-on, I've confirmed that the new implementation is correct, and consistent with Windows and X11.

@august64 august64 merged commit 8fd49a4 into rust-windowing:master Apr 17, 2018
august64 added a commit that referenced this pull request Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants