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

[X11] Create windows with a parent window #2246

Merged
merged 16 commits into from
Oct 9, 2022

Conversation

t-sin
Copy link
Contributor

@t-sin t-sin commented Apr 6, 2022

This PR can create windows with a user-specified parent window. It's intended to realize what discussed in issue #159 for X11.

This is a retry #2096. In that time I was not aware CI fails so passed long time, the master branch proceeds so much from that PR so I cannot follow changes.

TODO

  • Tested on all platforms changed
    • X11
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

@t-sin t-sin marked this pull request as ready for review April 6, 2022 23:21
examples/child_window.rs Outdated Show resolved Hide resolved
t-sin added a commit to t-sin/soyboy-sp.vst3 that referenced this pull request Apr 7, 2022
egui_sdl2_gl cannot create window with parent and with OpenGL context, it's because of the
specification of SDL2 itself. so I should not use egui_sdl2_gl. Now I use egui-glow (internally
uses egui-winit), but this don't support parent window, but I create Pull-Request to winit upstream
(rust-windowing/winit#2246).
For the merging that PR, as workarround, SoyBoy uses a folk of egui-glow on my GitHub accnount.
@t-sin t-sin force-pushed the with-parent-window-in-x11 branch 2 times, most recently from 573f967 to b2c3199 Compare April 15, 2022 22:41
@t-sin
Copy link
Contributor Author

t-sin commented Apr 15, 2022

All checks have passed! It's truly ready for review 🎊

@t-sin t-sin force-pushed the with-parent-window-in-x11 branch 2 times, most recently from bd5621d to ef6e8c8 Compare April 20, 2022 12:40
@t-sin
Copy link
Contributor Author

t-sin commented Apr 20, 2022

This PR followed the HEAD of master. Including document updates.

@t-sin t-sin force-pushed the with-parent-window-in-x11 branch from ef6e8c8 to d36181a Compare April 25, 2022 02:59
@t-sin t-sin force-pushed the with-parent-window-in-x11 branch from d36181a to a517678 Compare May 2, 2022 09:10
@t-sin
Copy link
Contributor Author

t-sin commented May 5, 2022

What does this PR stop? I’ll try to resolve that if I can.

@madsmtm
Copy link
Member

madsmtm commented May 6, 2022

We don't have a maintainer for X11 atm, so there's not really anyone to neither review nor accept the PR, sadly

@t-sin
Copy link
Contributor Author

t-sin commented May 7, 2022

Oh... It make sense.

@t-sin t-sin force-pushed the with-parent-window-in-x11 branch from a517678 to 904be7d Compare May 13, 2022 06:09
Copy link
Contributor

@dhardy dhardy left a comment

Choose a reason for hiding this comment

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

Not from your PR, but maybe you could also fix these errors?

#[doc(hidden)] is ignored on trait impl items

The code here... really, there's not much to review, besides the example.

Being able to visualise things is always nice, so I added softbuffer as a dev-dependency and modified the example. See my commits here: https://github.com/dhardy/winit/commits/with-parent-window-in-x11

x11-parent-window

That is, child windows are created at the mouse coordinates as a child of the window clicked in. Seems to work fine to me.

Maybe pull my commits into this PR? Although it's somewhat orthogonal; @madsmtm? (I also copied the softbuffer example into winit/examples.)

CHANGELOG.md Outdated
@@ -40,10 +40,12 @@ And please only add new entries to the top of this list, right below the `# Unre
- On iOS, send `RedrawEventsCleared` even if there are no redraw events, consistent with other platforms.
- **Breaking:** Replaced `Window::with_app_id` and `Window::with_class` with `Window::with_name` on `WindowBuilderExtUnix`.
- On Wayland and X11, fix window not resizing with `Window::set_inner_size` after calling `Window:set_resizable(false)`.
<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Left over from a merge?

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 sorry. Removed!

@@ -274,6 +274,9 @@ pub trait WindowBuilderExtUnix {

#[cfg(feature = "x11")]
fn with_x11_screen(self, screen_id: i32) -> Self;
#[cfg(feature = "x11")]
/// Build window with X11's parent window. Only relevant on X11.
fn with_x11_parent(self, parent_id: usize) -> Self;
Copy link
Contributor

@dhardy dhardy May 13, 2022

Choose a reason for hiding this comment

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

One other point worth making: is it possible to use the winit::WindowId here?

For X11 only, this doesn't matter much. If this feature gets generalised to other platforms (hopefully), then it would be better to use the WindowId.

Copy link
Member

@maroider maroider Jul 3, 2022

Choose a reason for hiding this comment

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

usize is likely the wrong type to use here. X11 window IDs are u32s, as far as I can tell (although x11-dl's typedefs do make things confusing, and the definition of XID in the headers wasn't fun to track down).

As of #2351, we can make a WindowId from arbitrary u64s, so using it instead should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One other point worth making: is it possible to use the winit::WindowId here?

As of #2351, we can make a WindowId from arbitrary u64s, so using it instead should be fine.

Good idea, thanks! I'll do that.

@dhardy
Copy link
Contributor

dhardy commented May 24, 2022

Further note: the child windows created by this PR are limited to the area of their parent. In general, it can be useful to have child windows without this restriction (e.g. menus may extend beyond the bounds of the parent).

@dhardy dhardy mentioned this pull request Jun 1, 2022
@t-sin
Copy link
Contributor Author

t-sin commented Jun 14, 2022

Sorry I did my project... I can do this PR starting this week end maybe.

@madsmtm
Copy link
Member

madsmtm commented Jun 23, 2022

Re adding softbuffer to our examples: I think it makes more sense to direct people toward it via. documentation, mostly since they don't support the same platforms as we do (glutin would be a better fit here), and is not a crate we're really in control of.

@kchibisov
Copy link
Member

Re adding softbuffer to our examples: I think it makes more sense to direct people toward it via. documentation, mostly since they don't support the same platforms as we do (glutin would be a better fit here), and is not a crate we're really in control of.

Using softbuffer should resolve issues with examples on Wayland, so it should simplify testing.

@maroider
Copy link
Member

I'm personally not entirely sold on softbuffer's current API, but I think the benefits of adding it to the examples (i.e. no more complaints about windows not showing up on wayland) are worthwhile.

@kchibisov
Copy link
Member

Yeah, I just want to have something that puts pixels into window, I'm not recommending softbuffer in particular.

@dhardy
Copy link
Contributor

dhardy commented Jun 28, 2022

mostly since they don't support the same platforms as we do (glutin would be a better fit here)

Will there ever be a perfect fit? Moreover, I'm skeptical that using a complex hardware-accelerated API as the default for visualizations is the most reliable choice, even if GL does work basically everywhere.

Given some direction I'm happy to author a different PR regarding softbuffer-in-winit, but it's simple enough that anyone here could do this.

@kchibisov
Copy link
Member

Given some direction I'm happy to author a different PR regarding softbuffer-in-winit, but it's simple enough that anyone here could do this.

If you feel like it you can go for it for sure.

CHANGELOG.md Outdated Show resolved Hide resolved
src/platform/x11.rs Outdated Show resolved Hide resolved
@t-sin t-sin force-pushed the with-parent-window-in-x11 branch 2 times, most recently from aded31f to 7dbf8fc Compare September 2, 2022 11:48
@@ -171,6 +172,9 @@ pub trait WindowBuilderExtX11 {
fn with_x11_visual<T>(self, visual_infos: *const T) -> Self;

fn with_x11_screen(self, screen_id: i32) -> Self;
#[cfg(feature = "x11")]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Also remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!!

Copy link
Member

Choose a reason for hiding this comment

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

This is still not removed.

Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Could you rebase. Should be good after that.

@t-sin
Copy link
Contributor Author

t-sin commented Sep 4, 2022

Rebased!

@@ -171,6 +172,9 @@ pub trait WindowBuilderExtX11 {
fn with_x11_visual<T>(self, visual_infos: *const T) -> Self;

fn with_x11_screen(self, screen_id: i32) -> Self;
#[cfg(feature = "x11")]
Copy link
Member

Choose a reason for hiding this comment

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

This is still not removed.

@@ -171,6 +172,9 @@ pub trait WindowBuilderExtX11 {
fn with_x11_visual<T>(self, visual_infos: *const T) -> Self;

fn with_x11_screen(self, screen_id: i32) -> Self;
#[cfg(feature = "x11")]
/// Build window with X11's parent window. Only relevant on X11.
Copy link
Member

Choose a reason for hiding this comment

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

We're inside the X11 extension.

Suggested change
/// Build window with X11's parent window. Only relevant on X11.
/// Build window with parent window.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! fixed.

@@ -120,7 +120,16 @@ impl UnownedWindow {
pl_attribs: PlatformSpecificWindowBuilderAttributes,
) -> Result<UnownedWindow, RootOsError> {
let xconn = &event_loop.xconn;
let root = event_loop.root;
// root should be a type ffi::Window and it is finally c_ulong.
Copy link
Member

Choose a reason for hiding this comment

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

Remove this comment entirely, there's no value in it. The WindowID thing is clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 126 to 128
// XID is defined as 32-bit value in the X11 protocol so
// there's no problem about higher bits truncation.
// cf. https://www.x.org/docs/XProtocol/proto.pdf
Copy link
Member

Choose a reason for hiding this comment

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

This comment also feels a bit strange. You can say WindowId is XID under the hood which doesn't exceed u32, so the conversion is lossless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@t-sin
Copy link
Contributor Author

t-sin commented Sep 18, 2022

Thanks @kchibisov for reviewing my some nits. I think these are fixed now (checked all diffs in the "Files changed" tab), but cargo check fails in my machine so I wait CI results...

EDITED: and sorry for late because of my private travelling...

@kchibisov kchibisov merged commit 71094e5 into rust-windowing:master Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

7 participants