From 46090ae2108992e5a53f6e670c951c6a4a55dd6c Mon Sep 17 00:00:00 2001 From: Lysander Treumann Date: Sat, 31 Jan 2026 03:31:45 +0100 Subject: [PATCH] Added "action on typing" setting to workspaces settings page. Added language information for action on typing for: English, German, Spanish, Swedish --- cosmic-settings/src/app.rs | 7 ++ .../src/pages/desktop/workspaces.rs | 80 ++++++++++++++++++- cosmic-settings/src/pages/mod.rs | 2 + i18n/de/cosmic_settings.ftl | 5 ++ i18n/en/cosmic_settings.ftl | 6 ++ i18n/es/cosmic_settings.ftl | 5 ++ i18n/sv/cosmic_settings.ftl | 5 ++ 7 files changed, 107 insertions(+), 3 deletions(-) diff --git a/cosmic-settings/src/app.rs b/cosmic-settings/src/app.rs index 3d2229c..afa5bc4 100644 --- a/cosmic-settings/src/app.rs +++ b/cosmic-settings/src/app.rs @@ -686,6 +686,13 @@ impl cosmic::Application for SettingsApp { return page.update(message).map(Into::into); } } + + #[cfg(feature = "page-workspaces")] + crate::pages::Message::Workspaces(message) => { + if let Some(page) = self.pages.page_mut::() { + return page.update(message).map(Into::into); + } + } }, #[cfg(feature = "wayland")] diff --git a/cosmic-settings/src/pages/desktop/workspaces.rs b/cosmic-settings/src/pages/desktop/workspaces.rs index a916939..904620f 100644 --- a/cosmic-settings/src/pages/desktop/workspaces.rs +++ b/cosmic-settings/src/pages/desktop/workspaces.rs @@ -7,9 +7,10 @@ use cosmic::{ Apply, Element, cosmic_config::{self, ConfigGet, ConfigSet}, iced::Length, - widget::{radio, settings, text}, + surface, + widget::{self, radio, settings, text}, }; -use cosmic_comp_config::workspace::{WorkspaceConfig, WorkspaceLayout, WorkspaceMode}; +use cosmic_comp_config::workspace::{Action, WorkspaceConfig, WorkspaceLayout, WorkspaceMode}; use cosmic_settings_page::Section; use cosmic_settings_page::{self as page, section}; use slab::Slab; @@ -18,16 +19,20 @@ use tracing::error; #[derive(Clone, Debug)] pub enum Message { + SetActionOnTyping(usize), SetWorkspaceMode(WorkspaceMode), SetWorkspaceLayout(WorkspaceLayout), SetShowName(bool), SetShowNumber(bool), + Surface(surface::Action), } pub struct Page { config: cosmic_config::Config, comp_config: cosmic_config::Config, comp_workspace_config: WorkspaceConfig, + action_on_typing_selections: Vec, + action_on_typing_active: Option, show_workspace_name: bool, show_workspace_number: bool, } @@ -43,6 +48,8 @@ impl Default for Page { WorkspaceConfig::default() }); let config = cosmic_config::Config::new("com.system76.CosmicWorkspaces", 1).unwrap(); + let action_on_typing_active = + into_active_selection(&comp_workspace_config.action_on_typing); let show_workspace_name = config.get("show_workspace_name").unwrap_or_else(|err| { if err.is_err() { error!(?err, "Failed to read config 'show_workspace_name'"); @@ -61,6 +68,12 @@ impl Default for Page { config, comp_config, comp_workspace_config, + action_on_typing_selections: vec![ + fl!("workspaces-overview", "none"), + fl!("workspaces-overview", "launcher"), + fl!("workspaces-overview", "applications"), + ], + action_on_typing_active, show_workspace_name, show_workspace_number, } @@ -73,6 +86,7 @@ impl page::Page for Page { sections: &mut SlotMap>, ) -> Option { Some(vec![ + sections.insert(action_on_typing()), sections.insert(multi_behavior()), sections.insert(workspace_orientation()), ]) @@ -97,7 +111,7 @@ impl Page { } } - pub fn update(&mut self, message: Message) { + pub fn update(&mut self, message: Message) -> cosmic::iced::Task { match message { Message::SetWorkspaceMode(value) => { self.comp_workspace_config.workspace_mode = value; @@ -107,6 +121,12 @@ impl Page { self.comp_workspace_config.workspace_layout = value; self.save_comp_config(); } + Message::SetActionOnTyping(value) => { + self.comp_workspace_config.action_on_typing = into_action(value); + self.action_on_typing_active = + into_active_selection(&self.comp_workspace_config.action_on_typing); + self.save_comp_config(); + } Message::SetShowName(value) => { self.show_workspace_name = value; if let Err(err) = self.config.set("show_workspace_name", value) { @@ -119,10 +139,64 @@ impl Page { error!(?err, "Failed to set config 'show_workspace_number'"); } } + Message::Surface(a) => { + return cosmic::task::message(crate::app::Message::Surface(a)); + } } + cosmic::iced::Task::none() } } +fn into_active_selection(action_on_typing: &Action) -> Option { + match action_on_typing { + Action::None => Some(0), + Action::OpenLauncher => Some(1), + Action::OpenApplications => Some(2), + } +} + +fn into_action(value: usize) -> Action { + match value { + 1 => Action::OpenLauncher, + 2 => Action::OpenApplications, + _ => Action::None, + } +} + +pub fn action_on_typing() -> Section { + let mut descriptions = Slab::new(); + + let action_on_typing = descriptions.insert(fl!("workspaces-overview", "action-on-typing")); + + Section::default() + .title(fl!("workspaces-overview")) + .descriptions(descriptions) + .view::(move |_binder, page, section| { + let descriptions = §ion.descriptions; + + settings::section() + .title(§ion.title) + .add( + settings::item::builder(&descriptions[action_on_typing]).control( + widget::dropdown::popup_dropdown( + &page.action_on_typing_selections, + page.action_on_typing_active, + Message::SetActionOnTyping, + cosmic::iced::window::Id::RESERVED, + Message::Surface, + |a| { + crate::app::Message::PageMessage(crate::pages::Message::Workspaces( + a, + )) + }, + ), + ), + ) + .apply(Element::from) + .map(crate::pages::Message::Workspaces) + }) +} + fn multi_behavior() -> Section { let mut descriptions = Slab::new(); diff --git a/cosmic-settings/src/pages/mod.rs b/cosmic-settings/src/pages/mod.rs index b453932..3a148af 100644 --- a/cosmic-settings/src/pages/mod.rs +++ b/cosmic-settings/src/pages/mod.rs @@ -103,6 +103,8 @@ pub enum Message { WindowManagement(desktop::window_management::Message), #[cfg(feature = "page-networking")] Wired(networking::wired::Message), + #[cfg(feature = "page-workspaces")] + Workspaces(desktop::workspaces::Message), // Common page functionality CloseContextDrawer, diff --git a/i18n/de/cosmic_settings.ftl b/i18n/de/cosmic_settings.ftl index 6e20055..a30a21c 100644 --- a/i18n/de/cosmic_settings.ftl +++ b/i18n/de/cosmic_settings.ftl @@ -335,6 +335,11 @@ focus-navigation = Fokus-Navigation workspaces = Arbeitsflächen .desc = Anzahl, Verhalten und Platzierung der Arbeitsflächen festlegen. +workspaces-overview = Arbeitsflächenübersicht + .action-on-typing = Reaktion auf Tippen + .none = Keine + .launcher = Starter öffnen + .applications = Anwendungen öffnen workspaces-behavior = Verhaltern der Arbeitsfläche .dynamic = Dynamische Arbeitsflächen .dynamic-desc = Entfernt automatisch leere Arbeitsflächen. diff --git a/i18n/en/cosmic_settings.ftl b/i18n/en/cosmic_settings.ftl index 07ba058..9be7a31 100644 --- a/i18n/en/cosmic_settings.ftl +++ b/i18n/en/cosmic_settings.ftl @@ -383,6 +383,12 @@ focus-navigation = Focus navigation workspaces = Workspaces .desc = Workspace orientation and behavior +workspaces-overview = Workspaces overview + .action-on-typing = Action on typing + .none = None + .launcher = Open Launcher + .applications = Open Applications + workspaces-behavior = Workspace behavior .dynamic = Dynamic workspaces .dynamic-desc = Automatically removes empty workspaces. diff --git a/i18n/es/cosmic_settings.ftl b/i18n/es/cosmic_settings.ftl index f64bc7a..0ba3155 100644 --- a/i18n/es/cosmic_settings.ftl +++ b/i18n/es/cosmic_settings.ftl @@ -335,6 +335,11 @@ focus-navigation = Navegación de enfoque workspaces = Espacios de trabajo .desc = Configurar el número de espacios de trabajo, comportamiento y ubicación. +workspaces-overview = Vista general de espacios de trabajo + .action-on-typing = Acción al escribir + .none = Ninguna + .launcher = Abrir lanzador + .applications = Abrir aplicaciones workspaces-behavior = Comportamiento de los espacios de trabajo .dynamic = Espacios de trabajo dinámicos .dynamic-desc = Elimina automáticamente los espacios de trabajo vacíos. diff --git a/i18n/sv/cosmic_settings.ftl b/i18n/sv/cosmic_settings.ftl index 29860e5..23561ba 100644 --- a/i18n/sv/cosmic_settings.ftl +++ b/i18n/sv/cosmic_settings.ftl @@ -266,6 +266,11 @@ x-hours = workspaces = Arbetsytor .desc = Orientering och beteende för arbetsytor +workspaces-overview = Arbetsyteöversikt + .action-on-typing = Åtgärd vid skrivning + .none = Ingen + .launcher = Öppna programstartare + .applications = Öppna applikationer workspaces-behavior = Beteende för arbetsytor .dynamic = Dynamiska arbetsytor .dynamic-desc = Tar automatiskt bort tomma arbetsytor.