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

Support window parenting on macOS, closes #3751 #3754

Merged
merged 9 commits into from
Mar 23, 2022
Merged

Conversation

probablykasper
Copy link
Member

@probablykasper probablykasper commented Mar 22, 2022

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

Closes #3751
Usage:

#[command]
pub fn create_child_window(id: String, app: AppHandle) {
  let main = app.get_window("main").unwrap();

  let child = window::WindowBuilder::new(&app, id, WindowUrl::default())
    .title("Child")
    .inner_size(400.0, 300.0);

  #[cfg(target_os = "macos")]
  let child = child.parent_window(main.ns_window().unwrap());
  #[cfg(target_os = "windows")]
  let child = child.parent_window(main.hwnd().unwrap());

  child.build();
}

Implemented it in the same way as for Windows, but it would be nice if usage was the same for all platforms. Not sure what the way to implement that would be, maybe RawWindowHandle? Would also be a breaking change, unless a different name is used.

@probablykasper probablykasper requested review from a team March 22, 2022 23:25
@probablykasper probablykasper requested a review from a team as a code owner March 22, 2022 23:25
@probablykasper
Copy link
Member Author

The example is failing because the Windows parent_window expects HWND but main.hwnd().unwrap() returns *mut std::ffi::c_void. Is that a bug with the Windows implementation?

@lucasfernog
Copy link
Member

@probablykasper I think the best solution is to change parent_window to return a HWND so I pushed that, but now the child window is not visible (it works if I remove the child.parent_window() call.

@probablykasper
Copy link
Member Author

Hm, no clue why that would be. Any idea if it works in tao atm?

.changes/parent-window-hwnd.md Outdated Show resolved Hide resolved
[skip ci]

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
@lucasfernog
Copy link
Member

Parent window directly on tao is weird but at least it shows the child window. I think wry is touching the window and messing with it too. Do you know if that's the case @amrbashir

@lucasfernog lucasfernog merged commit 4e807a5 into dev Mar 23, 2022
@lucasfernog lucasfernog deleted the parent-window-macos branch March 23, 2022 16:30
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.

[feat] Allow creation of child Window for macOS
4 participants