tauri-apps / tao

The TAO of cross-platform windowing. A library in Rust built for Tauri.
Apache License 2.0
1.57k stars 183 forks source link

feat: Add Linux method to use existing GTK window #938

Closed andrewbaxter closed 3 months ago

andrewbaxter commented 3 months ago

Fix #925

The existing Window::new() code can be roughly split into two parts: applying generic attributes to the window and connecting the window to the event loop. These can be fairly cleanly separated, so I did that - the new new_from_gtk_window method contains the latter, where new now just contains the former and calls new_from_gtk_window for the latter.

There are a few attributes that affect both the former and latter parts, and I presume in such cases the former is required for the latter to function properly. It's up to the caller to make sure that those prerequisites are met, but I'd like to add specific guidance to the new attribute struct documentation if this approach looks reasonable. (regarding transparent, cursor_moved, fullscreen, etc)

I also made set_skip_taskbar public since it seemed simpler than adding another attribute, but happy to go another way.

andrewbaxter commented 3 months ago

Thanks for the review! And whoops, I thought Draft: would make it a draft like in gitlab... getting rusty here.

andrewbaxter commented 3 months ago

I made the changes above, and made a few other small changes while testing:

~FWIW I think event_loop.rs and a couple other files I touched here aren't rustfmt'd (2 space indent, missing newlines) so I had to be careful when making changes - I think I've undone all the formatting but apologies in advance if I missed something.~ I'm not sure what happened, it looks like rust-analyzer ignored rustfmt.toml and reformatted everything, but now it's working again (and I fixed the formatting issues).

I think this is ready to go now.

andrewbaxter commented 3 months ago

With the changes to move methods into the traits, using an external gtk window now needs an invocation like:

<tao::window::Window as tao::platform::unix::WindowExtUnix<UserEvent>>::new_from_gtk_window(...)

which is pretty unintuitive. I'm not sure there's an easy way around that, but is there somewhere I could document that or provide an example?

amrbashir commented 3 months ago

you can juse use import the trait and use directly like this:

tao::platform::unix::WindowExtUnix;

let window = Window::from_gtk_window();
andrewbaxter commented 3 months ago

I think in this case the generic parameters for Window::from_gtk_window() are ambiguous so you need to use the explicit syntax, but good point... I guess rust-analyzer will quick-fix the import and suggest <Window as ...> so maybe it's more discoverable than I was thinking at first.

andrewbaxter commented 3 months ago

I made all the changes! I feel like this is pretty close now but let me know if there's anything else I missed. Thanks again for the reviews!

github-actions[bot] commented 3 months ago

Package Changes Through f770436291ac37e2dbe6934036f344934897e93f

There are 1 changes which include tao with patch

Planned Package Versions The following package releases are the planned based on the context of changes in this pull request. | package | current | next | |----|----|----| | tao | 0.28.1 | 0.28.2 |

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

amrbashir commented 3 months ago

I had to force push so I can sign your commits, for future contributions, you need to setup commit signing, then you can sign past commit like this for example.

andrewbaxter commented 3 months ago

Thanks! Yeah fwiw I sign my commits, but I don't include personal information in my key so github refuses to verify them.