feat(window_management): add show active window hint button

This commit is contained in:
TornaxO7 2024-10-07 19:37:35 +02:00 committed by GitHub
parent c6d6f5e788
commit a944359656
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 49 deletions

View file

@ -1784,7 +1784,7 @@ pub fn interface_density() -> Section<crate::pages::Message> {
Section::default()
.title(fl!("interface-density"))
.descriptions(descriptions)
.view::<Page>(move |_binder, page, section| {
.view::<Page>(move |_binder, _page, section| {
let descriptions = &section.descriptions;
let density = cosmic::config::interface_density();

View file

@ -8,33 +8,15 @@ pub mod wallpaper;
pub mod window_management;
pub mod workspaces;
use cosmic::{config::CosmicTk, cosmic_config::CosmicConfigEntry};
use cosmic_settings_page as page;
#[derive(Debug)]
#[allow(clippy::struct_excessive_bools)]
pub struct Page {
pub cosmic_config: Option<cosmic::cosmic_config::Config>,
pub cosmic_tk: CosmicTk,
}
pub struct Page {}
impl Default for Page {
fn default() -> Self {
let (cosmic_tk, cosmic_config) = CosmicTk::config().map_or_else(
|why| {
tracing::error!(?why, "failed to read CosmicTk config");
(CosmicTk::default(), None)
},
|config| match CosmicTk::get_entry(&config) {
Ok(tk) => (tk, Some(config)),
Err((_errors, tk)) => (tk, Some(config)),
},
);
Self {
cosmic_config,
cosmic_tk,
}
Self {}
}
}
@ -56,25 +38,8 @@ impl page::AutoBind<crate::pages::Message> for Page {
}
#[derive(Copy, Clone, Debug)]
pub enum Message {
ShowMaximizeButton(bool),
ShowMinimizeButton(bool),
}
pub enum Message {}
impl Page {
pub fn update(&mut self, message: Message) {
match message {
Message::ShowMaximizeButton(value) => {
if let Some(config) = self.cosmic_config.as_mut() {
let _res = self.cosmic_tk.set_show_maximize(config, value);
}
}
Message::ShowMinimizeButton(value) => {
if let Some(config) = self.cosmic_config.as_mut() {
let _res = self.cosmic_tk.set_show_minimize(config, value);
}
}
}
}
pub fn update(&mut self, _message: Message) {}
}

View file

@ -22,6 +22,9 @@ pub enum Message {
SaveFocusFollowsCursorDelay(bool),
SetFocusFollowsCursorDelay(String),
SetCursorFollowsFocus(bool),
ShowActiveWindowHint(bool),
ShowMaximizeButton(bool),
ShowMinimizeButton(bool),
}
pub struct Page {
@ -32,6 +35,7 @@ pub struct Page {
focus_follows_cursor_delay: u64,
focus_delay_text: String,
cursor_follows_focus: bool,
show_active_hint: bool,
}
impl Default for Page {
@ -63,6 +67,15 @@ impl Default for Page {
})
.unwrap_or(250);
let show_active_hint = comp_config
.get("active_hint")
.inspect_err(|err| {
if !matches!(err, cosmic_config::Error::NoConfigDirectory) {
error!(?err, "Failed to read config 'active_hint'")
}
})
.unwrap_or(true);
Page {
super_key_selections: vec![
fl!("super-key", "launcher"),
@ -76,6 +89,7 @@ impl Default for Page {
focus_follows_cursor_delay,
focus_delay_text: format!("{focus_follows_cursor_delay}"),
cursor_follows_focus,
show_active_hint,
}
}
}
@ -132,6 +146,28 @@ impl Page {
error!(?err, "Failed to set config 'cursor_follows_focus'");
}
}
Message::ShowMaximizeButton(value) => {
if let Ok(config) = cosmic::config::CosmicTk::config() {
let _res = cosmic::config::COSMIC_TK
.write()
.unwrap()
.set_show_maximize(&config, value);
}
}
Message::ShowMinimizeButton(value) => {
if let Ok(config) = cosmic::config::CosmicTk::config() {
let _res = cosmic::config::COSMIC_TK
.write()
.unwrap()
.set_show_minimize(&config, value);
}
}
Message::ShowActiveWindowHint(value) => {
self.show_active_hint = value;
if let Err(err) = self.comp_config.set("active_hint", value) {
error!(?err, "Failed to set config 'active_hint'");
}
}
}
}
}
@ -194,36 +230,38 @@ pub fn window_controls() -> Section<crate::pages::Message> {
let maximize = descriptions.insert(fl!("window-controls", "maximize"));
let minimize = descriptions.insert(fl!("window-controls", "minimize"));
let active_window_hint = descriptions.insert(fl!("window-controls", "active-window-hint"));
Section::default()
.title(fl!("window-controls"))
.descriptions(descriptions)
.view::<Page>(move |binder, _page, section| {
let desktop = binder
.page::<super::Page>()
.expect("desktop page not found");
.view::<Page>(move |_binder, page, section| {
let descriptions = &section.descriptions;
settings::section()
.title(&section.title)
.add(settings::item(
&descriptions[active_window_hint],
toggler(None, page.show_active_hint, Message::ShowActiveWindowHint),
))
.add(settings::item(
&descriptions[maximize],
toggler(
None,
desktop.cosmic_tk.show_maximize,
super::Message::ShowMaximizeButton,
cosmic::config::show_maximize(),
Message::ShowMaximizeButton,
),
))
.add(settings::item(
&descriptions[minimize],
toggler(
None,
desktop.cosmic_tk.show_minimize,
super::Message::ShowMinimizeButton,
cosmic::config::show_minimize(),
Message::ShowMinimizeButton,
),
))
.apply(Element::from)
.map(crate::pages::Message::Desktop)
.map(crate::pages::Message::WindowManagement)
})
}

View file

@ -307,6 +307,7 @@ super-key = Super key action
window-controls = Window Controls
.maximize = Show maximize button
.minimize = Show minimize button
.active-window-hint = Show active window hint
focus-navigation = Focus Navigation
.focus-follows-cursor = Focus follows cursor