input: Special characters dialog

This commit is contained in:
Ian Douglas Scott 2023-08-01 16:41:24 -07:00
parent 2a77cdacb4
commit e4d7c90f30
7 changed files with 253 additions and 64 deletions

View file

@ -1,8 +1,23 @@
use crate::app;
use cosmic::{
iced::{self, wayland::actions::window::SctkWindowSettings, window},
iced_sctk::commands,
iced_widget::core::layout,
};
use cosmic_settings_page as page;
pub mod keyboard;
mod mouse;
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct XkbConfig {
pub rules: String,
pub model: String,
pub layout: String,
pub variant: String,
pub options: Option<String>,
}
#[derive(Clone, Debug)]
pub enum Message {
SetAcceleration(bool),
@ -14,11 +29,16 @@ pub enum Message {
// seperate close message, to make sure another isn't closed?
ExpandInputSourcePopover(Option<String>),
OpenKeyboardShortcuts,
OpenSpecialCharacterDialog(keyboard::SpecialKey),
CloseSpecialCharacterDialog,
SpecialCharacterSelect(Option<&'static str>),
}
#[derive(derivative::Derivative)]
#[derivative(Default)]
pub struct Page {
// cosmic_config::Config
// Mouse
#[derivative(Default(value = "mouse::default_primary_button()"))]
primary_button: cosmic::widget::segmented_button::SingleSelectModel,
@ -32,11 +52,13 @@ pub struct Page {
expanded_source_popover: Option<String>,
#[derivative(Default(value = "keyboard::default_input_sources()"))]
sources: Vec<keyboard::InputSource>,
special_character_dialog: Option<keyboard::SpecialKey>,
xkb_options: Vec<String>,
}
impl Page {
// TODO
pub fn update(&mut self, message: Message) {
pub fn update(&mut self, message: Message) -> iced::Command<app::Message> {
match message {
Message::SetAcceleration(value) => {
self.acceleration = value;
@ -59,9 +81,45 @@ impl Page {
Message::ExpandInputSourcePopover(value) => {
self.expanded_source_popover = value;
}
// TODO Specially handled in app.rs
Message::OpenSpecialCharacterDialog(special_key) => {
self.special_character_dialog = Some(special_key);
let window_settings = SctkWindowSettings {
window_id: keyboard::SPECIAL_CHARACTER_DIALOGUE_ID,
app_id: Some("com.system76.CosmicSettings".to_string()),
title: Some(special_key.title()),
parent: Some(window::Id(0)),
autosize: false,
size_limits: layout::Limits::NONE
.min_width(300.0)
.max_width(800.0)
.min_height(200.0)
.max_height(1080.0),
size: (512, 420),
resizable: None,
client_decorations: true,
transparent: true,
};
return commands::window::get_window(window_settings);
}
Message::CloseSpecialCharacterDialog => {
self.special_character_dialog = None;
return commands::window::close_window(keyboard::SPECIAL_CHARACTER_DIALOGUE_ID);
}
Message::SpecialCharacterSelect(id) => {
if let Some(special_key) = self.special_character_dialog {
let prefix = special_key.prefix();
if let Some(idx) = self.xkb_options.iter().position(|x| x.starts_with(prefix)) {
self.xkb_options.remove(idx);
}
if let Some(id) = id {
self.xkb_options.push(id.to_string());
}
// TODO set in cosmic-config
}
}
Message::OpenKeyboardShortcuts => {}
}
iced::Command::none()
}
}