#How to hide window on focus lost and tray event without them interfering with each other?

1 messages · Page 1 of 1 (latest)

wraith dagger
#

Hi, I have a tray app that should open and close when the tray icon is clicked AND when focus is lost (clicking outside of the window)
the only issue is that my window handler will try to hide the window, while the tray handler will show it again because it just got hidden:

.on_system_tray_event(|app, event| match event {
            SystemTrayEvent::LeftClick { position, .. } => {
                if let Some(window) = app.get_window("main") {
                    if window.is_visible().unwrap() {
                        window.hide().unwrap();
                    } else {
                        window.show().unwrap();
                        window.set_focus().unwrap();
                    };
                }
            }
            // ...
        })
.on_window_event(|event| match event.event() {
            WindowEvent::Focused(focused) => {
                if !focused {
                    event.window().hide().unwrap();
                }
            }
            _ => (),
        })

any idea as to how i could make them not interfere with each other?

twin zealot
#

that's a super good question and i have no idea how one could solve that right now.

#

what i've seen other apps do (for example jetbrains toolbox which feels super clunky in general) is to have a smal timeout on the blur event

#

of course if the user holds the mouse button longer than that timeout it will still misbehave

#

but maybe the focus apis coming in 1.4 can help here 🤔 prob not

wraith dagger
#

oh hmmm
that kinda sucks rip

fast cliff
#

@wraith dagger Have you found a solution for this problem?

wraith dagger
#

nope, i've tried a few things but nothing worked

wraith dagger
#

i haven't worked on it at all for many months so maybe there's a solution now, but i don't think so

fast cliff
#

ok thanks

fast cliff
twin zealot
#

hmm, so what you're saying is that the tray event currently triggers twice?

#

it should only trigger once per click (so a combination of keyup and keydown, or simply just one of them)

#

So that would qualify as a bug already. - Edit: Please open a bug report about this if i understood you correctly.

#

And then more generally, yes we could split up the api into up and down though, if it would behave as expected i don't see much of a usecase tbh. feel free to open a feature request for it though to get feedback from others.

fast cliff
twin zealot
#

okay, so from my testing (a while back) this is not what happens. the tray even should indeed only trigger once.

#

but the way it works with the focus events above is really weird, but i can't remember that part from my testing, or if i even tested it.

fast cliff
#

I'll check with a keylogger and if correct, file a bug report.

fast cliff
#

Which is why the conflict happens in this particular scenario