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

refactor!: relax WindowBuilderExtUnix::with_transient_for window type #862

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/transient-for-relax-constraints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

**Breaking Change**: Changed `WindowBuilderExtUnix::with_transient_for` signature to take `&impl gtk::glib::IsA<gtk::Window>` instead of `gtk::ApplicationWindow` which covers more gtk window types and matches the underlying API call signature.
2 changes: 1 addition & 1 deletion examples/parentwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
let child_window_builder = child_window_builder.with_parent_window(parent_window.clone());

#[cfg(target_os = "linux")]
let child_window_builder = child_window_builder.with_transient_for(parent_window.clone());
let child_window_builder = child_window_builder.with_transient_for(parent_window);

let child_window = child_window_builder.build(&event_loop).unwrap();

Expand Down
7 changes: 4 additions & 3 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait WindowBuilderExtUnix {
fn with_skip_taskbar(self, skip: bool) -> WindowBuilder;
/// Set this window as a transient dialog for `parent`
/// <https://gtk-rs.org/gtk3-rs/stable/latest/docs/gdk/struct.Window.html#method.set_transient_for>
fn with_transient_for(self, parent: gtk::ApplicationWindow) -> WindowBuilder;
fn with_transient_for(self, parent: &impl gtk::glib::IsA<gtk::Window>) -> WindowBuilder;

/// Whether to enable or disable the internal draw for transparent window.
///
Expand Down Expand Up @@ -124,8 +124,9 @@ impl WindowBuilderExtUnix for WindowBuilder {
self
}

fn with_transient_for(mut self, parent: gtk::ApplicationWindow) -> WindowBuilder {
self.platform_specific.parent = Parent::ChildOf(parent);
fn with_transient_for(mut self, parent: &impl gtk::glib::IsA<gtk::Window>) -> WindowBuilder {
use gtk::glib::Cast;
self.platform_specific.parent = Parent::ChildOf(parent.clone().upcast());
self
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct KeyEventExtra {
#[derive(Clone)]
pub enum Parent {
None,
ChildOf(gtk::ApplicationWindow),
ChildOf(gtk::Window),
}

impl Default for Parent {
Expand Down
16 changes: 9 additions & 7 deletions src/platform_impl/linux/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ impl Window {
let app = &event_loop_window_target.app;
let window_requests_tx = event_loop_window_target.window_requests_tx.clone();
let draw_tx = event_loop_window_target.draw_tx.clone();
let window = gtk::ApplicationWindow::builder()

let mut window_builder = gtk::ApplicationWindow::builder()
.application(app)
.accept_focus(attributes.focused)
.build();
.accept_focus(attributes.focused);
if let Parent::ChildOf(parent) = pl_attribs.parent {
window_builder = window_builder.transient_for(&parent);
}

let window = window_builder.build();

let window_id = WindowId(window.id());
event_loop_window_target
.windows
Expand Down Expand Up @@ -212,10 +218,6 @@ impl Window {
window.hide();
}

if let Parent::ChildOf(parent) = pl_attribs.parent {
window.set_transient_for(Some(&parent));
}

// restore accept-focus after the window has been drawn
// if the window was initially created without focus
if !attributes.focused {
Expand Down
Loading