feat(desktop/options): implement window controls
This commit is contained in:
parent
958d9ba164
commit
82b96d1951
2 changed files with 38 additions and 8 deletions
|
|
@ -9,13 +9,34 @@ pub mod panel;
|
||||||
pub mod wallpaper;
|
pub mod wallpaper;
|
||||||
pub mod workspaces;
|
pub mod workspaces;
|
||||||
|
|
||||||
|
use cosmic::{config::CosmicTk, cosmic_config::CosmicConfigEntry};
|
||||||
use cosmic_settings_page as page;
|
use cosmic_settings_page as page;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug)]
|
||||||
#[allow(clippy::struct_excessive_bools)]
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
pub show_minimize_button: bool,
|
pub cosmic_config: Option<cosmic::cosmic_config::Config>,
|
||||||
pub show_maximize_button: bool,
|
pub cosmic_tk: CosmicTk,
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl page::Page<crate::pages::Message> for Page {
|
impl page::Page<crate::pages::Message> for Page {
|
||||||
|
|
@ -43,8 +64,17 @@ pub enum Message {
|
||||||
impl Page {
|
impl Page {
|
||||||
pub fn update(&mut self, message: Message) {
|
pub fn update(&mut self, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
Message::ShowMaximizeButton(value) => self.show_maximize_button = value,
|
Message::ShowMaximizeButton(value) => {
|
||||||
Message::ShowMinimizeButton(value) => self.show_minimize_button = 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use apply::Apply;
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::Length,
|
iced::Length,
|
||||||
theme,
|
theme,
|
||||||
widget::{button, container, horizontal_space, icon, list, row, settings, toggler},
|
widget::{button, container, horizontal_space, icon, row, settings, toggler},
|
||||||
Element,
|
Element,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ pub fn window_controls() -> Section<crate::pages::Message> {
|
||||||
&*descriptions[0],
|
&*descriptions[0],
|
||||||
toggler(
|
toggler(
|
||||||
None,
|
None,
|
||||||
desktop.show_minimize_button,
|
desktop.cosmic_tk.show_minimize,
|
||||||
Message::ShowMinimizeButton,
|
Message::ShowMinimizeButton,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
|
|
@ -98,7 +98,7 @@ pub fn window_controls() -> Section<crate::pages::Message> {
|
||||||
&*descriptions[1],
|
&*descriptions[1],
|
||||||
toggler(
|
toggler(
|
||||||
None,
|
None,
|
||||||
desktop.show_maximize_button,
|
desktop.cosmic_tk.show_maximize,
|
||||||
Message::ShowMaximizeButton,
|
Message::ShowMaximizeButton,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue