feat(shortcuts): add accessibility shortcuts subpage w/ zoom-in & zoom-out
This commit is contained in:
parent
2e99561d32
commit
62c16c0495
4 changed files with 149 additions and 7 deletions
|
|
@ -384,19 +384,27 @@ impl cosmic::Application for SettingsApp {
|
||||||
return page.update(message).map(Into::into);
|
return page.update(message).map(Into::into);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "page-accessibility")]
|
|
||||||
crate::pages::Message::AccessibilityMagnifier(message) => {
|
|
||||||
if let Some(page) = self.pages.page_mut::<accessibility::magnifier::Page>() {
|
|
||||||
return page.update(self.active_page, message).map(Into::into);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(feature = "page-about")]
|
#[cfg(feature = "page-about")]
|
||||||
crate::pages::Message::About(message) => {
|
crate::pages::Message::About(message) => {
|
||||||
if let Some(page) = self.pages.page_mut::<system::about::Page>() {
|
if let Some(page) = self.pages.page_mut::<system::about::Page>() {
|
||||||
return page.update(message).map(Into::into);
|
return page.update(message).map(Into::into);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "page-accessibility")]
|
||||||
|
crate::pages::Message::AccessibilityMagnifier(message) => {
|
||||||
|
if let Some(page) = self.pages.page_mut::<accessibility::magnifier::Page>() {
|
||||||
|
return page.update(self.active_page, message).map(Into::into);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "page-input")]
|
||||||
|
crate::pages::Message::AccessibilityShortcuts(message) => {
|
||||||
|
if let Some(page) = self
|
||||||
|
.pages
|
||||||
|
.page_mut::<input::keyboard::shortcuts::accessibility::Page>()
|
||||||
|
{
|
||||||
|
return page.update(message).map(Into::into);
|
||||||
|
}
|
||||||
|
}
|
||||||
crate::pages::Message::Appearance(message) => {
|
crate::pages::Message::Appearance(message) => {
|
||||||
if let Some(page) = self.pages.page_mut::<appearance::Page>() {
|
if let Some(page) = self.pages.page_mut::<appearance::Page>() {
|
||||||
return page.update(message).map(Into::into);
|
return page.update(message).map(Into::into);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
// Copyright 2024 System76 <info@system76.com>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
use super::{ShortcutMessage, ShortcutModel};
|
||||||
|
use cosmic::app::ContextDrawer;
|
||||||
|
use cosmic::{Element, Task};
|
||||||
|
use cosmic_settings_config::shortcuts::Action;
|
||||||
|
use cosmic_settings_page::{self as page, Section, section};
|
||||||
|
use slab::Slab;
|
||||||
|
|
||||||
|
pub struct Page {
|
||||||
|
model: super::Model,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Page {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
model: super::Model::default().actions(|defaults, keybindings| {
|
||||||
|
actions().iter().fold(Slab::new(), |mut slab, action| {
|
||||||
|
slab.insert(ShortcutModel::new(defaults, keybindings, action.clone()));
|
||||||
|
slab
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Page {
|
||||||
|
pub fn update(&mut self, message: ShortcutMessage) -> Task<crate::app::Message> {
|
||||||
|
self.model.update(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl page::Page<crate::pages::Message> for Page {
|
||||||
|
fn set_id(&mut self, entity: page::Entity) {
|
||||||
|
self.model.entity = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn info(&self) -> page::Info {
|
||||||
|
page::Info::new("accessibility-shortcuts", "input-keyboard-symbolic")
|
||||||
|
.title(fl!("accessibility"))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn content(
|
||||||
|
&self,
|
||||||
|
sections: &mut slotmap::SlotMap<section::Entity, Section<crate::pages::Message>>,
|
||||||
|
) -> Option<page::Content> {
|
||||||
|
Some(vec![sections.insert(shortcuts())])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn context_drawer(&self) -> Option<ContextDrawer<'_, crate::pages::Message>> {
|
||||||
|
self.model
|
||||||
|
.context_drawer(crate::pages::Message::AccessibilityShortcuts)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dialog(&self) -> Option<Element<'_, crate::pages::Message>> {
|
||||||
|
self.model
|
||||||
|
.dialog()
|
||||||
|
.map(|el| el.map(crate::pages::Message::AccessibilityShortcuts))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_context_drawer_close(&mut self) -> Task<crate::pages::Message> {
|
||||||
|
self.model.on_context_drawer_close();
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_enter(&mut self) -> Task<crate::pages::Message> {
|
||||||
|
_ = self.model.on_enter();
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_leave(&mut self) -> Task<crate::pages::Message> {
|
||||||
|
self.model.on_clear();
|
||||||
|
cosmic::iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.discard()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
|
fn subscription(
|
||||||
|
&self,
|
||||||
|
core: &cosmic::Core,
|
||||||
|
) -> cosmic::iced::Subscription<crate::pages::Message> {
|
||||||
|
self.model
|
||||||
|
.subscription(core)
|
||||||
|
.map(crate::pages::Message::AccessibilityShortcuts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl page::AutoBind<crate::pages::Message> for Page {}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub const fn actions() -> &'static [Action] {
|
||||||
|
&[Action::ZoomIn, Action::ZoomOut]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shortcuts() -> Section<crate::pages::Message> {
|
||||||
|
let mut descriptions = Slab::new();
|
||||||
|
|
||||||
|
// Make these searchable in the global settings search.
|
||||||
|
for action in actions() {
|
||||||
|
descriptions.insert(super::localize_action(action));
|
||||||
|
}
|
||||||
|
|
||||||
|
Section::default()
|
||||||
|
.descriptions(descriptions)
|
||||||
|
.view::<Page>(move |_binder, page, _section| {
|
||||||
|
page.model
|
||||||
|
.view()
|
||||||
|
.map(crate::pages::Message::AccessibilityShortcuts)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ mod common;
|
||||||
|
|
||||||
pub use common::{Model, ShortcutBinding, ShortcutMessage, ShortcutModel};
|
pub use common::{Model, ShortcutBinding, ShortcutMessage, ShortcutModel};
|
||||||
|
|
||||||
|
pub mod accessibility;
|
||||||
pub mod custom;
|
pub mod custom;
|
||||||
pub mod manage_windows;
|
pub mod manage_windows;
|
||||||
pub mod move_window;
|
pub mod move_window;
|
||||||
|
|
@ -42,6 +43,7 @@ pub struct Page {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Modified {
|
struct Modified {
|
||||||
|
accessibility: u16,
|
||||||
manage_windows: u16,
|
manage_windows: u16,
|
||||||
move_windows: u16,
|
move_windows: u16,
|
||||||
nav: u16,
|
nav: u16,
|
||||||
|
|
@ -51,6 +53,7 @@ struct Modified {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SubPages {
|
struct SubPages {
|
||||||
|
accessibility: page::Entity,
|
||||||
custom: page::Entity,
|
custom: page::Entity,
|
||||||
manage_window: page::Entity,
|
manage_window: page::Entity,
|
||||||
move_window: page::Entity,
|
move_window: page::Entity,
|
||||||
|
|
@ -77,6 +80,7 @@ pub enum Message {
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum Category {
|
pub enum Category {
|
||||||
|
Accessibility,
|
||||||
Custom,
|
Custom,
|
||||||
ManageWindow,
|
ManageWindow,
|
||||||
MoveWindow,
|
MoveWindow,
|
||||||
|
|
@ -94,6 +98,7 @@ impl Default for Page {
|
||||||
search_model: Model::default(),
|
search_model: Model::default(),
|
||||||
shortcuts_context: None,
|
shortcuts_context: None,
|
||||||
sub_pages: SubPages {
|
sub_pages: SubPages {
|
||||||
|
accessibility: page::Entity::null(),
|
||||||
custom: page::Entity::null(),
|
custom: page::Entity::null(),
|
||||||
manage_window: page::Entity::null(),
|
manage_window: page::Entity::null(),
|
||||||
move_window: page::Entity::null(),
|
move_window: page::Entity::null(),
|
||||||
|
|
@ -174,6 +179,10 @@ impl Page {
|
||||||
pub fn update(&mut self, message: Message) -> Task<crate::app::Message> {
|
pub fn update(&mut self, message: Message) -> Task<crate::app::Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::Category(category) => match category {
|
Message::Category(category) => match category {
|
||||||
|
Category::Accessibility => {
|
||||||
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.accessibility))
|
||||||
|
}
|
||||||
|
|
||||||
Category::Custom => {
|
Category::Custom => {
|
||||||
cosmic::task::message(crate::app::Message::Page(self.sub_pages.custom))
|
cosmic::task::message(crate::app::Message::Page(self.sub_pages.custom))
|
||||||
}
|
}
|
||||||
|
|
@ -240,6 +249,7 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
match action_category(custom_action) {
|
match action_category(custom_action) {
|
||||||
|
Some(Category::Accessibility) => self.modified.accessibility += 1,
|
||||||
Some(Category::ManageWindow) => self.modified.manage_windows += 1,
|
Some(Category::ManageWindow) => self.modified.manage_windows += 1,
|
||||||
Some(Category::MoveWindow) => self.modified.move_windows += 1,
|
Some(Category::MoveWindow) => self.modified.move_windows += 1,
|
||||||
Some(Category::Nav) => self.modified.nav += 1,
|
Some(Category::Nav) => self.modified.nav += 1,
|
||||||
|
|
@ -261,6 +271,7 @@ impl Page {
|
||||||
};
|
};
|
||||||
|
|
||||||
match action_category(action) {
|
match action_category(action) {
|
||||||
|
Some(Category::Accessibility) => self.modified.accessibility += 1,
|
||||||
Some(Category::ManageWindow) => self.modified.manage_windows += 1,
|
Some(Category::ManageWindow) => self.modified.manage_windows += 1,
|
||||||
Some(Category::MoveWindow) => self.modified.move_windows += 1,
|
Some(Category::MoveWindow) => self.modified.move_windows += 1,
|
||||||
Some(Category::Nav) => self.modified.nav += 1,
|
Some(Category::Nav) => self.modified.nav += 1,
|
||||||
|
|
@ -297,6 +308,7 @@ impl page::AutoBind<crate::pages::Message> for Page {
|
||||||
fn sub_pages(
|
fn sub_pages(
|
||||||
mut page: cosmic_settings_page::Insert<crate::pages::Message>,
|
mut page: cosmic_settings_page::Insert<crate::pages::Message>,
|
||||||
) -> cosmic_settings_page::Insert<crate::pages::Message> {
|
) -> cosmic_settings_page::Insert<crate::pages::Message> {
|
||||||
|
let accessibility = page.sub_page_with_id::<accessibility::Page>();
|
||||||
let custom = page.sub_page_with_id::<custom::Page>();
|
let custom = page.sub_page_with_id::<custom::Page>();
|
||||||
let manage_window = page.sub_page_with_id::<manage_windows::Page>();
|
let manage_window = page.sub_page_with_id::<manage_windows::Page>();
|
||||||
let move_window = page.sub_page_with_id::<move_window::Page>();
|
let move_window = page.sub_page_with_id::<move_window::Page>();
|
||||||
|
|
@ -305,6 +317,7 @@ impl page::AutoBind<crate::pages::Message> for Page {
|
||||||
let window_tiling = page.sub_page_with_id::<tiling::Page>();
|
let window_tiling = page.sub_page_with_id::<tiling::Page>();
|
||||||
|
|
||||||
let model = page.model.page_mut::<Page>().unwrap();
|
let model = page.model.page_mut::<Page>().unwrap();
|
||||||
|
model.sub_pages.accessibility = accessibility;
|
||||||
model.sub_pages.custom = custom;
|
model.sub_pages.custom = custom;
|
||||||
model.sub_pages.manage_window = manage_window;
|
model.sub_pages.manage_window = manage_window;
|
||||||
model.sub_pages.move_window = move_window;
|
model.sub_pages.move_window = move_window;
|
||||||
|
|
@ -407,6 +420,7 @@ impl Search {
|
||||||
fn shortcuts() -> Section<crate::pages::Message> {
|
fn shortcuts() -> Section<crate::pages::Message> {
|
||||||
let mut descriptions = Slab::new();
|
let mut descriptions = Slab::new();
|
||||||
|
|
||||||
|
let accessibility = descriptions.insert(fl!("accessibility"));
|
||||||
let custom_label = descriptions.insert(fl!("custom"));
|
let custom_label = descriptions.insert(fl!("custom"));
|
||||||
let manage_window_label = descriptions.insert(fl!("manage-windows"));
|
let manage_window_label = descriptions.insert(fl!("manage-windows"));
|
||||||
let move_window_label = descriptions.insert(fl!("move-windows"));
|
let move_window_label = descriptions.insert(fl!("move-windows"));
|
||||||
|
|
@ -430,6 +444,11 @@ fn shortcuts() -> Section<crate::pages::Message> {
|
||||||
// If the search input is not empty, show the category view, else the search results.
|
// If the search input is not empty, show the category view, else the search results.
|
||||||
let content = if page.search.input.is_empty() {
|
let content = if page.search.input.is_empty() {
|
||||||
settings::section()
|
settings::section()
|
||||||
|
.add(category_item(
|
||||||
|
Category::Accessibility,
|
||||||
|
&descriptions[accessibility],
|
||||||
|
page.modified.accessibility,
|
||||||
|
))
|
||||||
.add(category_item(
|
.add(category_item(
|
||||||
Category::ManageWindow,
|
Category::ManageWindow,
|
||||||
&descriptions[manage_window_label],
|
&descriptions[manage_window_label],
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ pub enum Message {
|
||||||
Accessibility(accessibility::Message),
|
Accessibility(accessibility::Message),
|
||||||
#[cfg(feature = "page-accessibility")]
|
#[cfg(feature = "page-accessibility")]
|
||||||
AccessibilityMagnifier(accessibility::magnifier::Message),
|
AccessibilityMagnifier(accessibility::magnifier::Message),
|
||||||
|
#[cfg(feature = "page-input")]
|
||||||
|
AccessibilityShortcuts(input::keyboard::shortcuts::ShortcutMessage),
|
||||||
#[cfg(feature = "page-about")]
|
#[cfg(feature = "page-about")]
|
||||||
About(system::about::Message),
|
About(system::about::Message),
|
||||||
Appearance(desktop::appearance::Message),
|
Appearance(desktop::appearance::Message),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue