Skip to content

Commit

Permalink
Implement oneshot mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thorio committed Mar 21, 2024
1 parent 65162ff commit 73589f4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
22 changes: 16 additions & 6 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,28 @@ frontend:
# text: 0xffffff
#
# behaviour:
#
# ## Whether or not to show the window when starting gravel
# start_hidden: false
#
# ## Automatically hides the window when it loses focus.
# auto_hide: true
# auto_hide: false
#
# ## Shows the internal score assigned to each hit,
# ## useful for debugging purposes.
# show_scores: false
# ## Exits the application instead of hiding the window.
# ## Requires external solution to start gravel when desired.
# exit_on_hide: false
#
# ## Time in milliseconds after hiding in which show requests
# ## should be ignored. This is a workaround for weird behaviour
# ## in X11 where hotkeys steal focus.
# window_hide_debounce: 200
#
# ## Automatically centers the window on the screen each time it is shown.
# auto_center_window: true
#
# ## Time in milliseconds after hiding in which show requests should be ignored.
# window_hide_debounce: 200
# ## Shows the internal score assigned to each hit,
# ## useful for debugging purposes.
# show_scores: false

## Providers to use. These are responsible for the results you get.
## Providers each yield different sets of results, so if you need more or
Expand Down
21 changes: 14 additions & 7 deletions gravel-frontend-fltk/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,25 @@ colors:
text: 0xffffff

behaviour:

## Whether or not to show the window when starting gravel
start_hidden: true
start_hidden: false

## Automatically hides the window when it loses focus.
auto_hide: true
auto_hide: false

## Shows the internal score assigned to each hit,
## useful for debugging purposes.
show_scores: false
## Exits the application instead of hiding the window.
## Requires external solution to start gravel when desired.
exit_on_hide: false

## Time in milliseconds after hiding in which show requests
## should be ignored. This is a workaround for weird behaviour
## in X11 where hotkeys steal focus.
window_hide_debounce: 200

## Automatically centers the window on the screen each time it is shown.
auto_center_window: true

## Time in milliseconds after hiding in which show requests should be ignored.
window_hide_debounce: 200
## Shows the internal score assigned to each hit,
## useful for debugging purposes.
show_scores: false
15 changes: 11 additions & 4 deletions gravel-frontend-fltk/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ pub const DEFAULT_CONFIG: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR")

/// Reads the [`DeserializedLayoutConfig`] from the adapter and transforms
/// it to the final [`Config`].
pub fn get_config(config: &PluginConfigAdapter) -> Config {
config.get::<Config>(DEFAULT_CONFIG)
pub fn get_config(adapter: &PluginConfigAdapter) -> Config {
let config = adapter.get::<Config>(DEFAULT_CONFIG);

if config.behaviour.start_hidden && config.behaviour.exit_on_hide {
log::warn!("frontend is configured to both start hidden and hide on exit, that doesn't make sense");
}

config
}

#[derive(Deserialize, Debug)]
pub struct Behaviour {
pub start_hidden: bool,
pub auto_hide: bool,
pub show_scores: bool,
pub auto_center_window: bool,
pub exit_on_hide: bool,
pub window_hide_debounce: Option<u64>,
pub auto_center_window: bool,
pub show_scores: bool,
}

#[derive(Deserialize, Debug)]
Expand Down
5 changes: 5 additions & 0 deletions gravel-frontend-fltk/src/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ impl FltkFrontend {
}

fn hide(&mut self) {
if self.config.behaviour.exit_on_hide {
self.ui.sender.send(Message::Exit);
return;
}

self.ui.window.platform_hide();
self.visible = false;
self.last_hide_time = SystemTime::now();
Expand Down

0 comments on commit 73589f4

Please sign in to comment.