Skip to content

[X11] Create windows with a parent window - #2246

Merged
kchibisov merged 16 commits into
rust-windowing:masterfrom
t-sin:with-parent-window-in-x11
Oct 9, 2022
Merged

kchibisov merged 16 commits into
rust-windowing:masterfrom
t-sin:with-parent-window-in-x11

Conversation

@t-sin

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

Copy link
Copy Markdown
Contributor

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
Comment thread examples/child_window.rs 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.
@msiglreith msiglreith added the DS - x11 Affects the X11 backend, or generally free Unix platforms label Apr 13, 2022
@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

t-sin commented Apr 15, 2022

Copy link
Copy Markdown
Contributor Author

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

Comment thread examples/child_window.rs Resolved
@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

t-sin commented Apr 20, 2022

Copy link
Copy Markdown
Contributor Author

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

t-sin commented May 5, 2022

Copy link
Copy Markdown
Contributor Author

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

@madsmtm

madsmtm commented May 6, 2022

Copy link
Copy Markdown
Member

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

t-sin commented May 7, 2022

Copy link
Copy Markdown
Contributor Author

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

@dhardy dhardy left a comment •

Copy link
Copy Markdown
Contributor

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.)

Comment thread CHANGELOG.md Outdated
- 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
Copy Markdown
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
Copy Markdown
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!

Comment thread src/platform/unix.rs Outdated
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;

@dhardy dhardy May 13, 2022 •

Copy link
Copy Markdown
Contributor

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.

@maroider maroider Jul 3, 2022 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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

dhardy commented May 24, 2022

Copy link
Copy Markdown
Contributor

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

t-sin commented Jun 14, 2022

Copy link
Copy Markdown
Contributor Author

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

@madsmtm

madsmtm commented Jun 23, 2022

Copy link
Copy Markdown
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.

@kchibisov

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@dhardy

dhardy commented Jun 28, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread CHANGELOG.md Resolved
Comment thread src/platform/x11.rs 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
Comment thread src/platform/x11.rs Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@t-sin
t-sin force-pushed the with-parent-window-in-x11 branch from 7dbf8fc to 5efd863 Compare September 3, 2022 14:57

@kchibisov kchibisov left a comment

Copy link
Copy Markdown
Member

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
t-sin force-pushed the with-parent-window-in-x11 branch from 5efd863 to d5b0d66 Compare September 4, 2022 01:23
@t-sin

t-sin commented Sep 4, 2022

Copy link
Copy Markdown
Contributor Author

Rebased!

Comment thread src/platform/x11.rs Outdated
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
Copy Markdown
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.

Comment thread src/platform/x11.rs Outdated

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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks! fixed.

Comment thread src/platform_impl/linux/x11/window.rs Outdated
) -> 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread src/platform_impl/linux/x11/window.rs Outdated
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
Copy Markdown
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
Copy Markdown
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
t-sin force-pushed the with-parent-window-in-x11 branch from d5b0d66 to c920d89 Compare September 18, 2022 00:58
@t-sin

t-sin commented Sep 18, 2022 •

Copy link
Copy Markdown
Contributor Author

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

DS - x11 Affects the X11 backend, or generally free Unix platforms

Development

Successfully merging this pull request may close these issues.

7 participants