Skip to content

Commit

Permalink
desktop/global_shortcuts: Reformat & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Dec 30, 2022
1 parent fde6399 commit 1849b0a
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/desktop/global_shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ use crate::{
struct NewShortcutInfo {
/// User-readable text describing what the shortcut does.
description: String,
/// The preferred shortcut trigger, defined as described by the "shortcuts" XDG specification. Optional.
/// The preferred shortcut trigger, defined as described by the "shortcuts"
/// XDG specification. Optional.
preferred_trigger: Option<String>,
}

/// Shortcut descriptor used to bind new shortcuts in [`GlobalShortcuts::bind_shortcuts`]
/// Shortcut descriptor used to bind new shortcuts in
/// [`GlobalShortcuts::bind_shortcuts`]
#[derive(Clone, Serialize, Type, Debug)]
pub struct NewShortcut(String, NewShortcutInfo);

Expand All @@ -39,9 +41,11 @@ impl NewShortcut {
)
}

/// Sets the preferred shortcut trigger, defined as described by the "shortcuts" XDG specification.
pub fn preferred_trigger(mut self, preferred_trigger: impl Into<Option<String>>) -> Self {
self.1.preferred_trigger = preferred_trigger.into();
/// Sets the preferred shortcut trigger, defined as described by the
/// "shortcuts" XDG specification.
#[must_use]
pub fn preferred_trigger<'a>(mut self, preferred_trigger: impl Into<Option<&'a str>>) -> Self {
self.1.preferred_trigger = preferred_trigger.into().map(ToOwned::to_owned);
self
}
}
Expand All @@ -51,13 +55,15 @@ impl NewShortcut {
struct ShortcutInfo {
/// User-readable text describing what the shortcut does.
description: String,
/// User-readable text describing how to trigger the shortcut for the client to render.
/// User-readable text describing how to trigger the shortcut for the client
/// to render.
trigger_description: String,
}

/// Struct that contains information about existing binded shortcut.
///
/// If you need to create a new shortcuts, take a look at [`NewShortcut`] instead.
/// If you need to create a new shortcuts, take a look at [`NewShortcut`]
/// instead.
#[derive(Clone, Deserialize, Type, Debug)]
pub struct Shortcut(String, ShortcutInfo);

Expand All @@ -72,7 +78,8 @@ impl Shortcut {
&self.1.description
}

/// User-readable text describing how to trigger the shortcut for the client to render.
/// User-readable text describing how to trigger the shortcut for the client
/// to render.
pub fn trigger_description(&self) -> &str {
&self.1.trigger_description
}
Expand Down Expand Up @@ -169,7 +176,8 @@ impl Deactivated {
}
}

/// Indicates that the information associated with some of the shortcuts has changed.
/// Indicates that the information associated with some of the shortcuts has
/// changed.
#[derive(Debug, Deserialize, Type)]
pub struct ShortcutsChanged(OwnedObjectPath, Vec<Shortcut>);

Expand Down Expand Up @@ -293,7 +301,8 @@ impl<'a> GlobalShortcuts<'a> {
receive_signal(self.inner(), "Deactivated").await
}

/// Signal emitted when information associated with some of the shortcuts has changed.
/// Signal emitted when information associated with some of the shortcuts
/// has changed.
///
/// # Specifications
///
Expand Down

0 comments on commit 1849b0a

Please sign in to comment.