feat: add shortcut for input source switch
This commit is contained in:
parent
d853267ef1
commit
661b487397
16 changed files with 93 additions and 24 deletions
|
|
@ -132,7 +132,11 @@ linux = [
|
|||
# Pages
|
||||
page-accessibility = ["dep:cosmic-protocols", "dep:sctk"]
|
||||
page-about = ["dep:cosmic-settings-system", "dep:hostname1-zbus", "dep:zbus"]
|
||||
page-bluetooth = ["dep:bluez-zbus", "dep:zbus", "dep:cosmic-settings-subscriptions"]
|
||||
page-bluetooth = [
|
||||
"dep:bluez-zbus",
|
||||
"dep:zbus",
|
||||
"dep:cosmic-settings-subscriptions",
|
||||
]
|
||||
page-date = ["dep:timedate-zbus", "dep:zbus"]
|
||||
page-default-apps = ["dep:mime-apps"]
|
||||
page-input = [
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
pub mod shortcuts;
|
||||
|
||||
use std::cmp;
|
||||
|
|
@ -76,6 +79,7 @@ pub enum SourceContext {
|
|||
pub type Locale = String;
|
||||
pub type Variant = String;
|
||||
pub type Description = String;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum LayoutSource {
|
||||
Base,
|
||||
|
|
@ -89,6 +93,9 @@ const KB_REPEAT_DELAY_MIN: u32 = 200;
|
|||
const KB_REPEAT_RATE_MAX: u32 = 45;
|
||||
const KB_REPEAT_RATE_MIN: u32 = 5;
|
||||
|
||||
const COSMIC_COMP_CONFIG: &str = "com.system76.CosmicComp";
|
||||
const COSMIC_COMP_CONFIG_VERSION: u64 = 1;
|
||||
|
||||
pub struct Page {
|
||||
entity: page::Entity,
|
||||
config: cosmic_config::Config,
|
||||
|
|
@ -103,7 +110,8 @@ pub struct Page {
|
|||
|
||||
impl Default for Page {
|
||||
fn default() -> Self {
|
||||
let config = cosmic_config::Config::new("com.system76.CosmicComp", 1).unwrap();
|
||||
let config =
|
||||
cosmic_config::Config::new(COSMIC_COMP_CONFIG, COSMIC_COMP_CONFIG_VERSION).unwrap();
|
||||
|
||||
Self {
|
||||
entity: page::Entity::null(),
|
||||
|
|
@ -209,7 +217,7 @@ fn popover_menu(id: DefaultKey) -> cosmic::Element<'static, Message> {
|
|||
color: background.component.divider.into(),
|
||||
width: 1.0,
|
||||
radius: cosmic.corner_radii.radius_s.into(),
|
||||
..Default::default()
|
||||
..Border::default()
|
||||
},
|
||||
shadow: Default::default(),
|
||||
}
|
||||
|
|
@ -609,26 +617,20 @@ impl Page {
|
|||
}
|
||||
|
||||
fn update_xkb_config(&mut self) {
|
||||
let mut new_layout = String::new();
|
||||
let mut new_variant = String::new();
|
||||
let result = update_xkb_config(
|
||||
&self.config,
|
||||
&mut self.xkb,
|
||||
&mut self
|
||||
.active_layouts
|
||||
.iter()
|
||||
.filter_map(|id| self.keyboard_layouts.get(*id))
|
||||
.map(|(locale, variant, _description, _source)| {
|
||||
(locale.as_str(), variant.as_str())
|
||||
}),
|
||||
);
|
||||
|
||||
for id in &self.active_layouts {
|
||||
if let Some((locale, variant, _description, _source)) = self.keyboard_layouts.get(*id) {
|
||||
new_layout.push_str(locale);
|
||||
new_layout.push(',');
|
||||
new_variant.push_str(variant);
|
||||
new_variant.push(',');
|
||||
}
|
||||
}
|
||||
|
||||
let _excess_comma = new_layout.pop();
|
||||
let _excess_comma = new_variant.pop();
|
||||
|
||||
self.xkb.layout = new_layout;
|
||||
self.xkb.variant = new_variant;
|
||||
|
||||
if let Err(err) = self.config.set("xkb_config", &self.xkb) {
|
||||
tracing::error!(?err, "Failed to set config 'xkb_config'");
|
||||
if let Err(why) = result {
|
||||
tracing::error!(?why, "Failed to set config 'xkb_config'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -792,3 +794,27 @@ fn keyboard_typing_assist() -> Section<crate::pages::Message> {
|
|||
.map(crate::pages::Message::Keyboard)
|
||||
})
|
||||
}
|
||||
|
||||
fn update_xkb_config(
|
||||
config: &cosmic_config::Config,
|
||||
xkb: &mut XkbConfig,
|
||||
active_layouts: &mut dyn Iterator<Item = (&str, &str)>,
|
||||
) -> Result<(), cosmic_config::Error> {
|
||||
let mut new_layout = String::new();
|
||||
let mut new_variant = String::new();
|
||||
|
||||
for (locale, variant) in active_layouts {
|
||||
new_layout.push_str(locale);
|
||||
new_layout.push(',');
|
||||
new_variant.push_str(variant);
|
||||
new_variant.push(',');
|
||||
}
|
||||
|
||||
let _excess_comma = new_layout.pop();
|
||||
let _excess_comma = new_variant.pop();
|
||||
|
||||
xkb.layout = new_layout;
|
||||
xkb.variant = new_variant;
|
||||
|
||||
config.set("xkb_config", xkb)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::iced::{Alignment, Length};
|
||||
use cosmic::widget::{self, button, icon, settings, text};
|
||||
use cosmic::{theme, Apply, Element, Task};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
//
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::{ShortcutBinding, ShortcutMessage, ShortcutModel};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::{ShortcutMessage, ShortcutModel};
|
||||
use cosmic::{Element, Task};
|
||||
use cosmic_settings_config::shortcuts::action::ResizeDirection;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
mod common;
|
||||
|
||||
pub use common::{Model, ShortcutBinding, ShortcutMessage, ShortcutModel};
|
||||
|
|
@ -649,6 +652,7 @@ fn localize_action(action: &Action) -> String {
|
|||
SystemAction::AppLibrary => fl!("system-shortcut", "app-library"),
|
||||
SystemAction::BrightnessDown => fl!("system-shortcut", "brightness-down"),
|
||||
SystemAction::BrightnessUp => fl!("system-shortcut", "brightness-up"),
|
||||
SystemAction::InputSourceSwitch => fl!("input-source-switch"),
|
||||
SystemAction::HomeFolder => fl!("system-shortcut", "home-folder"),
|
||||
SystemAction::KeyboardBrightnessDown => {
|
||||
fl!("system-shortcut", "keyboard-brightness-down")
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
//
|
||||
use super::{ShortcutMessage, ShortcutModel};
|
||||
use cosmic::{Element, Task};
|
||||
use cosmic_settings_config::shortcuts::action::Direction;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::{ShortcutMessage, ShortcutModel};
|
||||
use cosmic::{Element, Task};
|
||||
use cosmic_settings_config::shortcuts::action::{Direction, FocusDirection};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::{ShortcutMessage, ShortcutModel};
|
||||
use cosmic::{Element, Task};
|
||||
use cosmic_settings_config::shortcuts::action::System as SystemAction;
|
||||
|
|
@ -94,6 +97,7 @@ pub const fn actions() -> &'static [Action] {
|
|||
Action::System(SystemAction::BrightnessUp),
|
||||
Action::System(SystemAction::KeyboardBrightnessDown),
|
||||
Action::System(SystemAction::KeyboardBrightnessUp),
|
||||
Action::System(SystemAction::InputSourceSwitch),
|
||||
Action::System(SystemAction::Screenshot),
|
||||
Action::System(SystemAction::Terminal),
|
||||
Action::System(SystemAction::HomeFolder),
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2024 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::{ShortcutMessage, ShortcutModel};
|
||||
use cosmic::{Element, Task};
|
||||
use cosmic_settings_config::shortcuts::action::Orientation;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::app;
|
||||
use cosmic::{
|
||||
cosmic_config::{self, ConfigGet, ConfigSet},
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::iced::{Alignment, Length};
|
||||
use cosmic::widget::{self, row, settings, text};
|
||||
use cosmic::{Apply, Element};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::cosmic_config::ConfigGet;
|
||||
use cosmic::iced::{Alignment, Length};
|
||||
use cosmic::widget::{self, row, settings, text};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue