Bevy / Winit - Open GUI Without Focus

429 Views Asked by At

I'm writing various graphical tests in Bevy. Each spawns the GUI, runs for a few seconds, and then exits the app and moves on to the next.

I love being able to visually check its doing what I think, but when each starts it steals focus from VS Code. This means I can't code while the tests are running, or use a 'hot-reload' workflow.

I understand that Bevy uses Winit under the hood, but couldn't find anything in either the bevy plugin or Winit source on opening a window without focus, or surrendering focus once it is open.

My ideal solution would be a simple setting in the WindowDescriptor:

App::new()
  .insert_resource(WindowDescriptor {
    
    // this would be awesome
    open_without_focus:true, 

    ..Default::default()
    })
  .run()

A few notes:

  • I'm on Windows 11 but it would be great to have a platform agnostic solution.
  • I have tried various Always On Top solutions like PowerToys but this doesn't help with focus.
1

There are 1 best solutions below

0
On

Not ideal, but am finding invoking Alt+Escape with enigo better than nothing:

use enigo::*;

pub fn surrender_focus(){
  let mut enigo = Enigo::new();
  enigo.key_down(Key::Alt);
  enigo.key_click(Key::Escape);
  enigo.key_up(Key::Alt);
}

fn main(){
  App::new()
    .add_startup_system(surrender_focus)
    .run()
}