diff --git a/README.md b/README.md index e5a3d5f..d14aeb4 100644 --- a/README.md +++ b/README.md @@ -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", ], diff --git a/anyrun/src/main.rs b/anyrun/src/main.rs index 8c7d1bc..1894d87 100644 --- a/anyrun/src/main.rs +++ b/anyrun/src/main.rs @@ -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: >k::Application, runtime_data: Rc } }); - // 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: >k::Application, runtime_data: Rc 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( diff --git a/examples/config.ron b/examples/config.ron index 3c82a5b..9330766 100644 --- a/examples/config.ron +++ b/examples/config.ron @@ -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 // `/plugins` directory or with an absolute path to just load the file the path points to.