Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make most window types have a child window #1919

Merged
merged 15 commits into from Sep 18, 2021
Merged

Conversation

JAicewizard
Copy link
Contributor

This does a couple of things.
It adds the notion of parent and child windows. all non-main windows have a parent window.
All non-main windows have their coordinate space shifted, so that the origin is the location of the main window.
This is usefull in almost all usecases.

This also removes the option to change the level after the fact. At least the GTK backend doesnt support this, and it would just be extra work to move all the widgets to the new window. I also dont think there is any usecase for this.

This solves positioning not working in wayland (#1757) and resolves the discussion over at #1824.

Copy link
Collaborator

@jneem jneem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'd probably wait a bit to see if anyone else objects...

@@ -102,13 +102,23 @@ pub(crate) struct WindowHandle {
/// a view. Also, this is better for hosted applications such as VST.
nsview: WeakPtr,
idle_queue: Weak<Mutex<Vec<IdleKind>>>,
parent: Option<Box<crate::WindowHandle>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Box is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because mac is different. It would be an infinitely big struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the others already have a reference in between the window handle and this option, mac doesnt.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does mac need to store parent handle though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To change the coordinate space relative to the parent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, it's because on mac you've put the parent directly in the WindowHandle. Why not put it in ViewState, so it's more similar to the other platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont exactly know how to get that from the WindowHandle :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't test because I don't have a mac, but looking at set_focused_text_field gives a hint, I think:

// Here, self is a &WindowHandle
if let Some(view) = self.nsview.load().as_ref() {
    let state: *mut c_void = *view.get_ivar("viewState");
    let state = &mut (*(state as *mut ViewState));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes I see, thanks! pushed the changes

@JAicewizard
Copy link
Contributor Author

JAicewizard commented Aug 14, 2021

Id actualy first like to do some discussion about popups, to popups also need to have a parent? and do they also need to be in the parents coordinate space? Thinking about this again it seems that popups maybe should use the global coordinate space.

@JAicewizard
Copy link
Contributor Author

nvm I forgot that we have modal as a 3rd window type, not popup :) Ignore my last message

@cmyr cmyr self-requested a review August 15, 2021 18:28
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Manmeet Maan <49202620+Maan2003@users.noreply.github.com>
@maan2003
Copy link
Collaborator

I believe x11 backend position translation is TODO?

@JAicewizard
Copy link
Contributor Author

X11 tooltips dont work, I could add the set_position conversion but it wouldn't do anything.

@maan2003
Copy link
Collaborator

no, I think they work now (at least the sub_window example does)

@JAicewizard
Copy link
Contributor Author

also the tooltip? I get

Aug 16 13:12:37.291 ERROR druid::win_handler: failed to create sub window: '[druid-shell/src/backend/x11/application.rs:430] self.state'
Aug 16 13:12:37.291 ERROR druid_shell::backend::x11::application: Error handling event: CONFIGURE_NOTIFY - failed to get window: No window with id 69206063```

@maan2003

This comment has been minimized.

@JAicewizard
Copy link
Contributor Author

For me it gets opened as a non-floating window, but that's fine-ish.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay as discussed I do have some longer-term ambitions here, but in the meantime this seems reasonable!

Comment on lines 1218 to 1219
// TODO: Maybe collin can get this into a state where modal windows follow the parent?
// There is an API to do child windows, (https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you can move the parent while a modal is presented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tooltips and dropdowns suffer from the same issue, we expect them to be closed when moving a window but ATM that is upto the user to program. It might still be worth implementing for those? if not Ill remove the comment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM that is upto the user to program.

is it possible? We don't have any windowmove events

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhh oh. If I am going to be implementing proper parent tracking, I can only do this for GTK and with some research probably X11. Others will have to help me on different platforms.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should give windowmove events and then the user should do whatever they like (move with the window or close the popup)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, lets put that in another MR to not bloat this one.

druid-shell/src/backend/mac/window.rs Outdated Show resolved Hide resolved
Co-authored-by: Colin Rofls <colin@cmyr.net>
@jneem
Copy link
Collaborator

jneem commented Sep 16, 2021

This can be merged, right? (modulo conflicts)

@JAicewizard
Copy link
Contributor Author

I fixed the conflicts, I think this should be ok to merge now.

@jneem jneem merged commit 53321e2 into linebender:master Sep 18, 2021
@CryZe
Copy link
Contributor

CryZe commented Sep 20, 2021

This PR somehow killed DropDown entirely on at least Windows. It doesn't do anything anymore (no window spawns).

Update: WS_CHILD somehow needs to be WS_POPUP now for the window to appear.

@JAicewizard
Copy link
Contributor Author

JAicewizard commented Sep 20, 2021

WindowLevel::DropDown? I didnt even change anything with those, the parent is completely ignored. Are you sure that it is this PR specifically?

EDIT: Could be that I broke something during the merge conflicts?

@CryZe
Copy link
Contributor

CryZe commented Sep 20, 2021

Nvm, you are right. This was indeed already broken on master one commit before your PR got merged. I'll look into deeper bisecting this later today (or I'll just send a PR, since even on the older commit when it still worked, it was far from looking like a drop down in the first place)

@sjoshid
Copy link
Contributor

sjoshid commented Sep 20, 2021

Tooltip in sub-windows example definitely got worse in Windows. Reverting the latest commit on sub_windows.rs example does fix it, but maybe it breaks in Gtk?

ctx.window().get_position()
+ window_pos.to_vec2()
+ cursor_size.to_vec2(),
(window_pos.to_vec2() + cursor_size.to_vec2()).to_point(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjoshid these lines? That means the coordinate space for tool-tips isn't calculated correctly. what doesnt work anymore?

Copy link
Contributor

@sjoshid sjoshid Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for being vague. Yes those lines. The location of tooltip is way off target.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be some DPI scaling? I cant really test but ill check if I can spot something related to that.

Copy link
Contributor

@sjoshid sjoshid Sep 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem, at least on Windows, is that the cursor position received in TooltipController is in window coords. So we need to go from window coords to screen coords because screen coords is what Windows expect when you create a tooltip.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that conversion happens in win/window.rs. So that should be handled. Instead of adding the parent window coordinates in the users code we do it in druid_shell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because those coordinates are in global space while they should be in window space. they are converted to global space by druid_shell not the client code. This was part of the change, so it should work. Maybe it cant get the parents state? that could be an issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution i gave in previous comment is basically the old code. That was dumb on my part. lol. The previous code didnt make much sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where in shell is this conversion happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sjoshid added a commit to sjoshid/druid that referenced this pull request Sep 21, 2021
* Implementation differs slightly from linebender#1919. Unlike linebender#1919, this does NOT store parent window handle in `WindowState`. If you want to access parent window handle AFTER creating window use [GetParent](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getparent).
* Handles scaling.
* Tooltip example in nursery tested with these changes. If this is accepted, I'll make changes in nursery too.
This was referenced Sep 21, 2021
maan2003 added a commit that referenced this pull request Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants