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

How can I do something when widget or window lose focus? #3250

Closed
Horbin-Magician opened this issue Aug 10, 2023 · 3 comments
Closed

How can I do something when widget or window lose focus? #3250

Horbin-Magician opened this issue Aug 10, 2023 · 3 comments
Labels
a:builtin elements The runtime data structures related to the items (mO,bT)

Comments

@Horbin-Magician
Copy link
Contributor

My platform is windows11, and using Slint with Rust.
I want to hide my window when it loss focus. But I can't find any callback or api to do so.
Please help me.
(ps: It is also difficult for me to change the backend of Slint. I try to change the SLINT_BACKEND environment variable of Windows11, but there is no change. How can I know what backend Slint is using?)

@ogoffart ogoffart added the a:builtin elements The runtime data structures related to the items (mO,bT) label Aug 10, 2023
@ogoffart
Copy link
Member

I think it's currently not possible to hide the window when it looses focus. This is a feature we'd need to add.
When a widget loses focus, the has-focus property change. Again it is not possible to detect change, but there are workarounds: #112 (comment)

(ps: It is also difficult for me to change the backend of Slint. I try to change the SLINT_BACKEND environment variable of Windows11, but there is no change. How can I know what backend Slint is using?)

One way to know the backend is to use SLINT_DEBUG_PERFORMANCE env variable. For example, set it to
SLINT_DEBUG_PERFORMANCE=refresh_lazy,console,overlay and it should print in the console what backend is used.

@Horbin-Magician
Copy link
Contributor Author

I think it's currently not possible to hide the window when it looses focus. This is a feature we'd need to add. When a widget loses focus, the has-focus property change. Again it is not possible to detect change, but there are workarounds: #112 (comment)

(ps: It is also difficult for me to change the backend of Slint. I try to change the SLINT_BACKEND environment variable of Windows11, but there is no change. How can I know what backend Slint is using?)

One way to know the backend is to use SLINT_DEBUG_PERFORMANCE env variable. For example, set it to SLINT_DEBUG_PERFORMANCE=refresh_lazy,console,overlay and it should print in the console what backend is used.

Thanks for your reply! SLINT_DEBUG_PERFORMANCE env variable is very helpful for me. However, the workarounds #112 (comment) do not work now.

    export component Demo inherits Window {
        callback my_callback(bool) -> color;
        my_callback(x) => { red; }
        background: my_callback(touch.has-hover);
        touch := TouchArea {  height: 50%;  }
    }

The 'my_callback' method causes an error: Call of impure callback 'my-callback'.

Now, I'm trying to implement this function with TouchArea, and really hope a "focus changing" callback (like ActivationChange event in Qt) can be added. (Maybe at least for FocusScope?)

@ogoffart
Copy link
Member

The 'my_callback' method causes an error: Call of impure callback 'my-callback'.

right, you need to annotate my_callback as pure

Now, I'm trying to implement this function with TouchArea, and really hope a "focus changing" callback

Yes, this would be a good addition: #1236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:builtin elements The runtime data structures related to the items (mO,bT)
Projects
None yet
Development

No branches or pull requests

2 participants