breadbox: steal focus on open, close on unfocus
Switch KeyboardMode to Exclusive so Hyprland hands keyboard focus to breadbox immediately on creation. Add an EventControllerFocus on the window that calls close() the moment focus leaves (click outside, alt-tab, compositor focus change, etc.).
This commit is contained in:
parent
e6204e94a9
commit
ba8273b2ca
1 changed files with 10 additions and 1 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -331,7 +331,7 @@ fn run_ui(entries: Vec<(String, String)>) {
|
||||||
|
|
||||||
window.init_layer_shell();
|
window.init_layer_shell();
|
||||||
window.set_layer(Layer::Overlay);
|
window.set_layer(Layer::Overlay);
|
||||||
window.set_keyboard_mode(KeyboardMode::OnDemand);
|
window.set_keyboard_mode(KeyboardMode::Exclusive);
|
||||||
window.set_anchor(Edge::Top, true);
|
window.set_anchor(Edge::Top, true);
|
||||||
window.set_exclusive_zone(-1);
|
window.set_exclusive_zone(-1);
|
||||||
|
|
||||||
|
|
@ -474,6 +474,15 @@ fn run_ui(entries: Vec<(String, String)>) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Close when focus leaves the window (click outside, alt-tab, etc.)
|
||||||
|
let window_foc = window.clone();
|
||||||
|
let focus_ctrl = gtk4::EventControllerFocus::new();
|
||||||
|
focus_ctrl.connect_leave(move |_| {
|
||||||
|
cleanup_pid();
|
||||||
|
window_foc.close();
|
||||||
|
});
|
||||||
|
window.add_controller(focus_ctrl);
|
||||||
|
|
||||||
// Cleanup pid when window is destroyed for any reason
|
// Cleanup pid when window is destroyed for any reason
|
||||||
window.connect_destroy(|_| cleanup_pid());
|
window.connect_destroy(|_| cleanup_pid());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue