diff --git a/justfile b/justfile index d1dda03..9835c8e 100644 --- a/justfile +++ b/justfile @@ -23,9 +23,6 @@ metainfo-dst := clean(rootdir / prefix) / 'share' / 'metainfo' / metainfo icons-src := 'res' / 'icons' / 'hicolor' icons-dst := clean(rootdir / prefix) / 'share' / 'icons' / 'hicolor' -shortcuts-src := 'res' / 'com.system76.CosmicTerm.Shortcuts' / 'v1' -shortcuts-dst := clean(rootdir / prefix) / 'share' / 'cosmic' / 'com.system76.CosmicTerm.Shortcuts' / 'v1' - # Default recipe which runs `just build-release` default: build-release @@ -70,8 +67,6 @@ install: install -Dm0755 {{bin-src}} {{bin-dst}} install -Dm0644 {{desktop-src}} {{desktop-dst}} install -Dm0644 {{metainfo-src}} {{metainfo-dst}} - install -Dm0644 {{shortcuts-src}}/defaults {{shortcuts-dst}}/defaults - install -Dm0644 {{shortcuts-src}}/custom {{shortcuts-dst}}/custom for size in `ls {{icons-src}}`; do \ install -Dm0644 "{{icons-src}}/$size/apps/{{APPID}}.svg" "{{icons-dst}}/$size/apps/{{APPID}}.svg"; \ done diff --git a/res/com.system76.CosmicTerm.Shortcuts/v1/custom b/res/com.system76.CosmicTerm.Shortcuts/v1/custom deleted file mode 100644 index 0967ef4..0000000 --- a/res/com.system76.CosmicTerm.Shortcuts/v1/custom +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/src/config.rs b/src/config.rs index 9963994..39e6568 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::sync::OnceLock; -use crate::{fl, localize::LANGUAGE_SORTER}; +use crate::{fl, localize::LANGUAGE_SORTER, shortcuts::Shortcuts}; pub const CONFIG_VERSION: u64 = 1; pub const COSMIC_THEME_DARK: &str = "COSMIC Dark"; @@ -236,6 +236,8 @@ pub struct Config { pub syntax_theme_light: String, pub focus_follow_mouse: bool, pub default_profile: Option, + #[serde(default)] + pub shortcuts_custom: Shortcuts, } impl Default for Config { @@ -259,6 +261,7 @@ impl Default for Config { syntax_theme_light: COSMIC_THEME_LIGHT.to_string(), use_bright_bold: false, default_profile: None, + shortcuts_custom: Shortcuts::default(), } } } diff --git a/src/main.rs b/src/main.rs index 70b787c..6fbbcd7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,7 +162,10 @@ fn main() -> Result<(), Box> { } }; - let (shortcuts_config_handler, shortcuts_config) = shortcuts::load(); + let shortcuts_config = shortcuts::ShortcutsConfig { + defaults: shortcuts::Shortcuts::default(), + custom: config.shortcuts_custom.clone(), + }; let startup_options = if let Some(shell_program) = shell_program_opt { let options = tty::Options { @@ -192,7 +195,6 @@ fn main() -> Result<(), Box> { let flags = Flags { config_handler, config, - shortcuts_config_handler, shortcuts_config, startup_options, term_config, @@ -220,7 +222,6 @@ Options: pub struct Flags { config_handler: Option, config: Config, - shortcuts_config_handler: Option, shortcuts_config: shortcuts::ShortcutsConfig, startup_options: Option, term_config: term::Config, @@ -351,7 +352,6 @@ pub enum Message { ColorSchemeRenameSubmit, ColorSchemeTabActivate(widget::segmented_button::Entity), Config(Config), - ShortcutsConfig(shortcuts::ShortcutsConfig), Copy(Option), CopyOrSigint(Option), CopyPrimary(Option), @@ -451,7 +451,6 @@ pub struct App { pane_model: TerminalPaneGrid, config_handler: Option, config: Config, - shortcuts_config_handler: Option, shortcuts_config: shortcuts::ShortcutsConfig, key_binds: HashMap, app_themes: Vec, @@ -561,9 +560,13 @@ impl App { } fn save_shortcuts_custom(&mut self) { - match &self.shortcuts_config_handler { + self.config.shortcuts_custom = self.shortcuts_config.custom.clone(); + match &self.config_handler { Some(config_handler) => { - if let Err(err) = config_handler.set("custom", &self.shortcuts_config.custom) { + if let Err(err) = config_handler.set( + "shortcuts_custom", + &self.config.shortcuts_custom, + ) { log::warn!("failed to save shortcuts custom config: {}", err); } } @@ -1705,7 +1708,6 @@ impl Application for App { pane_model, config_handler: flags.config_handler, config: flags.config, - shortcuts_config_handler: flags.shortcuts_config_handler, shortcuts_config: flags.shortcuts_config, key_binds, app_themes, @@ -2023,19 +2025,21 @@ impl Application for App { } Message::Config(config) => { if config != self.config { + let shortcuts_changed = + config.shortcuts_custom != self.config.shortcuts_custom; log::info!("update config"); //TODO: update syntax theme by clearing tabs, only if needed self.config = config; + if shortcuts_changed { + self.shortcuts_config = shortcuts::ShortcutsConfig { + defaults: shortcuts::Shortcuts::default(), + custom: self.config.shortcuts_custom.clone(), + }; + self.key_binds = key_binds(&self.shortcuts_config); + } return self.update_config(); } } - Message::ShortcutsConfig(config) => { - if config != self.shortcuts_config { - log::info!("update shortcuts config"); - self.shortcuts_config = config; - self.key_binds = key_binds(&self.shortcuts_config); - } - } Message::Copy(entity_opt) => { if let Some(tab_model) = self.pane_model.active() { let entity = entity_opt.unwrap_or_else(|| tab_model.active()); @@ -3169,7 +3173,6 @@ impl Application for App { fn subscription(&self) -> Subscription { struct ConfigSubscription; - struct ShortcutsConfigSubscription; struct TerminalEventSubscription; Subscription::batch([ @@ -3216,21 +3219,6 @@ impl Application for App { } Message::Config(update.config) }), - cosmic_config::config_subscription::<_, shortcuts::ShortcutsConfig>( - TypeId::of::(), - shortcuts::SHORTCUTS_CONFIG_ID.into(), - shortcuts::SHORTCUTS_CONFIG_VERSION, - ) - .map(|update| { - if !update.errors.is_empty() { - log::debug!( - "errors loading shortcuts config {:?}: {:?}", - update.keys, - update.errors - ); - } - Message::ShortcutsConfig(update.config) - }), match &self.dialog_opt { Some(dialog) => dialog.subscription(), None => Subscription::none(), diff --git a/src/shortcuts.rs b/src/shortcuts.rs index 024a0f5..c65c00f 100644 --- a/src/shortcuts.rs +++ b/src/shortcuts.rs @@ -2,7 +2,6 @@ use cosmic::widget::menu::key_bind::{KeyBind, Modifier}; use cosmic::{ - cosmic_config::{self, CosmicConfigEntry, cosmic_config_derive::CosmicConfigEntry}, iced::keyboard::{Key, Modifiers}, iced_core::keyboard::key::Named, }; @@ -11,9 +10,6 @@ use std::collections::{BTreeMap, HashMap}; use crate::Action; -pub const SHORTCUTS_CONFIG_ID: &str = "com.system76.CosmicTerm.Shortcuts"; -pub const SHORTCUTS_CONFIG_VERSION: u64 = 1; - #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub enum ModifierName { Ctrl, @@ -167,7 +163,7 @@ pub struct ResolvedBinding { pub source: BindingSource, } -#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize, CosmicConfigEntry)] +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] pub struct ShortcutsConfig { pub defaults: Shortcuts, pub custom: Shortcuts, @@ -231,25 +227,6 @@ impl ShortcutsConfig { } } -pub fn load() -> (Option, ShortcutsConfig) { - match cosmic_config::Config::new(SHORTCUTS_CONFIG_ID, SHORTCUTS_CONFIG_VERSION) { - Ok(config_handler) => { - let config = match ShortcutsConfig::get_entry(&config_handler) { - Ok(config) => config, - Err((errors, config)) => { - log::info!("errors loading shortcuts config: {:?}", errors); - config - } - }; - (Some(config_handler), config) - } - Err(err) => { - log::error!("failed to create shortcuts config handler: {}", err); - (None, ShortcutsConfig::default()) - } - } -} - pub fn action_label(action: KeyBindAction) -> &'static str { match action { KeyBindAction::Unbind => "Unbind",