Option to close window when a click is received outside the main box

This commit is contained in:
Kirottu
2023-05-01 15:28:39 +03:00
parent 0aabb332c9
commit 465ee1d266
3 changed files with 22 additions and 2 deletions

View File

@@ -98,6 +98,9 @@ by managing it in Nix/home-manager, and using the full path, like this (in hm):_
// Hide the plugin info panel
hide_plugin_info: true,
// Close window when a click outside the main box is received
close_on_click: false,
plugins: [
"${pkgs.anyrun}/lib/libapplications.so",
],

View File

@@ -24,6 +24,7 @@ struct Config {
hide_icons: bool,
hide_plugin_info: bool,
ignore_exclusive_zones: bool,
close_on_click: bool,
layer: Layer,
}
@@ -513,8 +514,18 @@ fn activate(app: &gtk::Application, runtime_data: Rc<RefCell<Option<RuntimeData>
}
});
// Show the window initially, so it gets allocated and configured
window.show_all();
// If the option is enabled, close the window when any click is received
// that is outside the bounds of the main box
if config.close_on_click {
window.connect_button_press_event(move |window, event| {
if event.window() == window.window() {
window.close();
Inhibit(true)
} else {
Inhibit(false)
}
});
}
// Create widgets here for proper positioning
window.connect_configure_event(move |window, event| {
@@ -557,6 +568,9 @@ fn activate(app: &gtk::Application, runtime_data: Rc<RefCell<Option<RuntimeData>
entry.grab_focus(); // Grab the focus so typing is immediately accepted by the entry box
false
});
// Show the window initially, so it gets allocated and configured
window.show_all();
}
fn handle_matches(

View File

@@ -23,6 +23,9 @@ Config(
// Hide the plugin info panel
hide_plugin_info: false,
// Close window when a click outside the main box is received
close_on_click: false,
// List of plugins to be loaded by default, can be specified with a relative path to be loaded from the
// `<anyrun config dir>/plugins` directory or with an absolute path to just load the file the path points to.