#Focus only happens sometimes

3 messages · Page 1 of 1 (latest)

runic marten
#

I have the app in background and i have a key combination to open it. Up till there everything is good. When i open i need to focus on the app but if am in other app for example vscode where i am writing something and then do my combo the app will show up but not focus. Is there a way to avoid this problem?
My code related to focus is this:

In TS:

focus.value = await listen("focus_box", (event) => {
    appWindow.setFocus();
    searchRef.value.focus();
  })

And in rust:

let main_window = launch_app.get_window("main").unwrap();
                        let screen = main_window.current_monitor().unwrap().unwrap();
                        let screen_position = screen.position();
                        let screen_size = PhysicalSize::<i32> {
                            width: screen.size().width as i32,
                            height: screen.size().height as i32,
                        };
                        let window_size = PhysicalSize::<i32> {
                            width: main_window.outer_size().unwrap().width as i32,
                            height: main_window.outer_size().unwrap().height as i32,
                        };

                        let new_position = PhysicalPosition {
                            x: screen_position.x
                                + ((screen_size.width / 2) - (window_size.width / 2)),
                            y: screen_position.y + 100,
                        };

                        main_window.set_position(new_position).unwrap();
                        main_window.set_always_on_top(true).unwrap();
                        main_window.show().unwrap();
                        main_window.emit("focus_box", "").unwrap();
#

The position thing is to center the window and have a offset

#

I hope it's not interfering with the focus