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

Adds the ability to disable/enable window interactions #6694

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

TheColorRed
Copy link
Contributor

@TheColorRed TheColorRed commented Oct 31, 2024

This allows the user to enable/disable interactions with the window. This is useful for displaying a dialog box that. This is useful in conjunction with always-on-top and PR #6675.

Example Slint:

mod dialog {
    slint::slint! {
        export component MyDialog inherits Window {
          skip-taskbar: true;

          width: 200px;
          height: 200px;
        }
    }
}

slint::slint! {
  import { Button } from "std-widgets.slint";

  export component AppWindow inherits Window {
    callback show-dialog;

    min-width: 200px;
    min-height: 200px;

    Button {
      text: "Click me!";
      clicked => {
        root.show-dialog();
        // root.disabled = true;
      }
    }
  }
}

Example Rust (Might be overkill 😃)

use std::sync::Arc;

pub fn main() -> Result<(), slint::PlatformError> {
    let app_window = AppWindow::new()?;
    let app = Arc::new(app_window);

    let window_ref = app.clone();
    app.clone().on_show_dialog(move || {
        let dialog = dialog::MyDialog::new().unwrap();
        window_ref.clone().window().set_disabled(true);
        let window_ref = window_ref.clone();
        dialog.window().on_close_requested(move || {
            window_ref.clone().window().set_disabled(false);
            slint::CloseRequestResponse::HideWindow
        });

        let _ = dialog.show();
    });

    app.clone().run()?;
    Ok(())
}

@TheColorRed TheColorRed marked this pull request as ready for review November 1, 2024 00:31
@ogoffart
Copy link
Member

ogoffart commented Nov 7, 2024

I'm wondering if that's really the right API to create modal dialog.
We might need a more complex API in rust/C++ to create modal dialog that prevent interaction on their parent. I think this is the typical usecase.

@hunger
Copy link
Member

hunger commented Nov 7, 2024

With wayland + portals we will also need a way to register external windows as "modal windows" on top of application windows. So maybe we can pass in a optional (os-) window handle or something instead of a bool?

E.g. file selection in a program using a portal can pop up a file dialog that logically belongs to the application asking for a file, but is actually a different process providing the window. That needs to be handled properly to make sure the right windows get selected when switching between applications.

Kai-Uwe blogged about KDE doing this recently: https://blog.broulik.de/2024/11/little-wayland-things/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants