mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 12:50:04 -04:00
On X11, allow building window with parent
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::os::raw;
|
||||
use std::{ptr, sync::Arc};
|
||||
|
||||
use crate::window::WindowId;
|
||||
use crate::{
|
||||
event_loop::{EventLoopBuilder, EventLoopWindowTarget},
|
||||
monitor::MonitorHandle,
|
||||
@@ -171,6 +172,8 @@ pub trait WindowBuilderExtX11 {
|
||||
fn with_x11_visual<T>(self, visual_infos: *const T) -> Self;
|
||||
|
||||
fn with_x11_screen(self, screen_id: i32) -> Self;
|
||||
/// Build window with parent window.
|
||||
fn with_parent(self, parent_id: WindowId) -> Self;
|
||||
|
||||
/// Build window with the given `general` and `instance` names.
|
||||
///
|
||||
@@ -227,6 +230,12 @@ impl WindowBuilderExtX11 for WindowBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_parent(mut self, parent_id: WindowId) -> Self {
|
||||
self.platform_specific.parent_id = Some(parent_id.0);
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_override_redirect(mut self, override_redirect: bool) -> Self {
|
||||
self.platform_specific.override_redirect = override_redirect;
|
||||
|
||||
@@ -95,6 +95,8 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
#[cfg(feature = "x11")]
|
||||
pub screen_id: Option<i32>,
|
||||
#[cfg(feature = "x11")]
|
||||
pub parent_id: Option<WindowId>,
|
||||
#[cfg(feature = "x11")]
|
||||
pub base_size: Option<Size>,
|
||||
#[cfg(feature = "x11")]
|
||||
pub override_redirect: bool,
|
||||
@@ -115,6 +117,8 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||
#[cfg(feature = "x11")]
|
||||
screen_id: None,
|
||||
#[cfg(feature = "x11")]
|
||||
parent_id: None,
|
||||
#[cfg(feature = "x11")]
|
||||
base_size: None,
|
||||
#[cfg(feature = "x11")]
|
||||
override_redirect: false,
|
||||
|
||||
@@ -119,7 +119,12 @@ impl UnownedWindow {
|
||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||
) -> Result<UnownedWindow, RootOsError> {
|
||||
let xconn = &event_loop.xconn;
|
||||
let root = event_loop.root;
|
||||
let root = if let Some(id) = pl_attribs.parent_id {
|
||||
// WindowId is XID under the hood which doesn't exceed u32, so this conversion is lossless
|
||||
u64::from(id) as _
|
||||
} else {
|
||||
event_loop.root
|
||||
};
|
||||
|
||||
let mut monitors = xconn.available_monitors();
|
||||
let guessed_monitor = if monitors.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user