diff --git a/crates/tauri-runtime-cef/src/cef_impl.rs b/crates/tauri-runtime-cef/src/cef_impl.rs index fb4d77f7d..c39b57550 100644 --- a/crates/tauri-runtime-cef/src/cef_impl.rs +++ b/crates/tauri-runtime-cef/src/cef_impl.rs @@ -3005,6 +3005,18 @@ pub(crate) fn create_webview( browser.set_bounds(bounds.as_ref()); + // On Linux, explicitly set parent after creation as set_as_child may not work correctly + #[cfg(target_os = "linux")] + { + // Try to set parent - if window handle isn't available yet, this will be a no-op + // but the browser should become visible once the handle is available + browser.set_parent(&window); + // Ensure browser is visible after setting parent + browser.set_visible(1); + // Set bounds again after reparenting to ensure correct size + browser.set_bounds(bounds.as_ref()); + } + #[cfg(any(not(target_os = "macos"), feature = "macos-private-api"))] if webview_attributes.transparent { browser.set_background_color(0x00000000); @@ -3052,6 +3064,7 @@ pub(crate) fn create_webview( }), ); + println!(" browser view"); let browser_view = browser_view_create( Some(&mut client), Some(&url), diff --git a/crates/tauri-runtime-cef/src/cef_webview/linux.rs b/crates/tauri-runtime-cef/src/cef_webview/linux.rs index 67fd90094..e22e9ce1b 100644 --- a/crates/tauri-runtime-cef/src/cef_webview/linux.rs +++ b/crates/tauri-runtime-cef/src/cef_webview/linux.rs @@ -91,6 +91,8 @@ impl CefBrowserExt for cef::Browser { rect.width as u32, rect.height as u32, ); + // Ensure window is mapped and raised after setting bounds + (xlib.XMapRaised)(display, xid as xlib::Window); (xlib.XFlush)(display); (xlib.XCloseDisplay)(display); } @@ -161,6 +163,9 @@ impl CefBrowserExt for cef::Browser { }; let parent_xid = parent.window_handle() as u64; + if parent_xid == 0 { + return; + } let Some(xlib) = X11.as_ref() else { return; @@ -172,6 +177,24 @@ impl CefBrowserExt for cef::Browser { return; } + // Check if window exists before reparenting + let mut root: xlib::Window = 0; + let mut parent_window: xlib::Window = 0; + let mut children: *mut xlib::Window = std::ptr::null_mut(); + let mut nchildren: u32 = 0; + let status = (xlib.XQueryTree)( + display, + xid as xlib::Window, + &mut root, + &mut parent_window, + &mut children, + &mut nchildren, + ); + + if status != 0 && !children.is_null() { + (xlib.XFree)(children as *mut std::ffi::c_void); + } + (xlib.XReparentWindow)( display, xid as xlib::Window, @@ -179,6 +202,9 @@ impl CefBrowserExt for cef::Browser { 0, 0, ); + + // Ensure window is mapped and raised after reparenting + (xlib.XMapRaised)(display, xid as xlib::Window); (xlib.XFlush)(display); (xlib.XCloseDisplay)(display); }