Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ impl cosmic::Application for CosmicPortal {
subscription::Event::Config(config) => self.update(Msg::ConfigSubUpdate(config)),
subscription::Event::Accent(_)
| subscription::Event::IsDark(_)
| subscription::Event::HighContrast(_) => cosmic::iced::Task::none(),
| subscription::Event::HighContrast(_)
| subscription::Event::ButtonPlacement(_) => cosmic::iced::Task::none(),
subscription::Event::Init(tx) => {
self.tx = Some(tx);
Task::none()
Expand Down Expand Up @@ -322,6 +323,10 @@ impl cosmic::Application for CosmicPortal {
new_theme.is_high_contrast,
));
}
// TODO: only send if value actually changed
msgs.push(subscription::Event::ButtonPlacement(
crate::Settings::new().button_placement,
));
{
if let Some(tx) = self.tx.clone() {
tokio::spawn(async move {
Expand Down
26 changes: 26 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ const APPEARANCE_NAMESPACE: &str = "org.freedesktop.appearance";
const COLOR_SCHEME_KEY: &str = "color-scheme";
const ACCENT_COLOR_KEY: &str = "accent-color";
const CONTRAST_KEY: &str = "contrast";
const BUTTON_PLACEMENT_KEY: &str = "button-placement";

struct Settings {
pub color_scheme: ColorScheme,
pub contrast: Contrast,
pub accent: Srgba<f64>,
pub button_placement: (Vec<String>, Vec<String>),
}

impl Settings {
Expand All @@ -214,8 +216,25 @@ impl Settings {
ColorScheme::PreferLight
},
accent: cosmic.accent_color().into_format(),
button_placement: {
let mut leading = Vec::<String>::new();
if cosmic::config::show_minimize() {
leading.push("minimize".to_string());
}
if cosmic::config::show_maximize() {
leading.push("maximize".to_string());
}
leading.push("close".to_string());
(Vec::<String>::default(), leading)
},
}
}

fn button_placement_key_to_value(&self) -> zvariant::OwnedValue {
let temp: &zvariant::Value = &self.button_placement.clone().into();
let value = temp.try_into().unwrap();
return value;
}
}

#[zbus::interface(name = "org.freedesktop.impl.portal.Settings")]
Expand Down Expand Up @@ -256,6 +275,10 @@ impl Settings {
}) {
inner.insert(ACCENT_COLOR_KEY.to_string(), value);
}
inner.insert(
BUTTON_PLACEMENT_KEY.to_string(),
self.button_placement_key_to_value(),
);
map.insert(APPEARANCE_NAMESPACE.to_string(), inner);
}
map
Expand All @@ -274,6 +297,9 @@ impl Settings {
blue: self.accent.blue,
})
.map_err(|e| zbus::fdo::Error::Failed(e.to_string())),
(APPEARANCE_NAMESPACE, BUTTON_PLACEMENT_KEY) => {
Ok(self.button_placement_key_to_value())
}
_ => Err(zbus::fdo::Error::Failed(
"Unknown namespace or key".to_string(),
)),
Expand Down
22 changes: 19 additions & 3 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use tokio::sync::mpsc::Receiver;
use zbus::{Connection, zvariant};

use crate::{
ACCENT_COLOR_KEY, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY, CONTRAST_KEY, ColorScheme, Contrast,
DBUS_NAME, DBUS_PATH, Settings, access::Access, config, file_chooser::FileChooser,
screencast::ScreenCast, screenshot::Screenshot, wayland,
ACCENT_COLOR_KEY, APPEARANCE_NAMESPACE, BUTTON_PLACEMENT_KEY, COLOR_SCHEME_KEY, CONTRAST_KEY,
ColorScheme, Contrast, DBUS_NAME, DBUS_PATH, Settings, access::Access, config,
file_chooser::FileChooser, screencast::ScreenCast, screenshot::Screenshot, wayland,
};

#[derive(Clone, Debug)]
Expand All @@ -23,6 +23,7 @@ pub enum Event {
Accent(Srgba),
IsDark(bool),
HighContrast(bool),
ButtonPlacement((Vec<String>, Vec<String>)),
Config(config::Config),
Init(tokio::sync::mpsc::Sender<Event>),
}
Expand Down Expand Up @@ -175,6 +176,21 @@ pub(crate) async fn process_changes(
)
.await?;
}
Event::ButtonPlacement(placement_key) => {
let object_server = conn.object_server();
let iface_ref = object_server.interface::<_, Settings>(DBUS_PATH).await?;
let mut iface = iface_ref.get_mut().await;
iface.button_placement = placement_key;

iface
.setting_changed(
iface_ref.signal_emitter(),
APPEARANCE_NAMESPACE,
BUTTON_PLACEMENT_KEY,
iface.button_placement_key_to_value().into(),
)
.await?;
}
Event::Config(config) => {
if let Err(err) = output.send(Event::Config(config)).await {
log::error!("Error sending config update: {:?}", err)
Expand Down