Skip to content
Open
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
3 changes: 2 additions & 1 deletion i18n/en/cosmic_ext_applet_external_monitor_brightness.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dark_mode = Dark Mode
gamma_map = Gamma Map
refresh = Refresh
refresh = Refresh
no_monitor = No external monitors found
31 changes: 0 additions & 31 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
use crate::config::{self, Config, MonitorConfig};
use crate::monitor;
use crate::monitor::{DisplayId, EventToSub, MonitorInfo, ScreenBrightness};
use anyhow::anyhow;
use cosmic::app::{Core, Task};
use cosmic::cosmic_config::Config as CosmicConfig;
use cosmic::cosmic_config::CosmicConfigEntry;
use cosmic::cosmic_theme::{THEME_MODE_ID, ThemeMode};
use cosmic::iced::window::Id;
use cosmic::iced::{Limits, Subscription};
Expand Down Expand Up @@ -168,7 +166,6 @@ pub enum AppMsg {

ConfigChanged(Config),
ThemeModeConfigChanged(ThemeMode),
SetDarkMode(bool),

SetScreenBrightness(DisplayId, f32),
ToggleMinMaxBrightness(DisplayId),
Expand Down Expand Up @@ -298,34 +295,6 @@ impl cosmic::Application for AppState {
AppMsg::ThemeModeConfigChanged(config) => {
self.theme_mode_config = config;
}
AppMsg::SetDarkMode(dark) => {
#[allow(dead_code)]
fn set_theme_mode(mode: &ThemeMode) -> anyhow::Result<()> {
let home_dir = dirs::home_dir().ok_or(anyhow!("no home dir"))?;

let helper = cosmic::cosmic_config::Config::with_custom_path(
THEME_MODE_ID,
ThemeMode::VERSION,
home_dir.join(".config"),
)?;

mode.write_entry(&helper)?;

Ok(())
}

fn set_theme_mode2(mode: &ThemeMode) -> anyhow::Result<()> {
let helper = ThemeMode::config()?;
mode.write_entry(&helper)?;
Ok(())
}

self.theme_mode_config.is_dark = dark;

if let Err(e) = set_theme_mode2(&self.theme_mode_config) {
error!("can't write theme mode {e}");
}
}
AppMsg::SubscriptionReady((monitors, sender)) => {
self.monitors = monitors
.into_iter()
Expand Down
36 changes: 8 additions & 28 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use crate::app::{AppMsg, AppState, MonitorState};
use crate::fl;
use crate::icon::{icon_high, icon_low, icon_medium, icon_off};
use cosmic::Element;
use cosmic::applet::padded_control;
use cosmic::iced::{Alignment, Length};
use cosmic::widget::{
button, column, container, divider, horizontal_space, icon, mouse_area, row, slider, text,
toggler, tooltip,
button, column, container, horizontal_space, icon, mouse_area, row, slider, text, toggler,
tooltip,
};

impl AppState {
Expand Down Expand Up @@ -59,18 +58,13 @@ impl AppState {
}

pub fn popup_view(&self) -> Element<AppMsg> {
column()
.padding(10)
.push_maybe(self.monitors_view())
.push_maybe(
(!self.monitors.is_empty()).then(|| padded_control(divider::horizontal::default())),
)
.push(self.dark_mode_view())
.into()
column().padding(10).push(self.monitors_view()).into()
}

fn monitors_view(&self) -> Option<Element<AppMsg>> {
(!self.monitors.is_empty()).then(|| {
fn monitors_view(&self) -> Element<AppMsg> {
if self.monitors.is_empty() {
column().push(text(fl!("no_monitor"))).into()
} else {
column()
.padding(8)
.extend(
Expand All @@ -79,7 +73,7 @@ impl AppState {
.map(|(id, monitor)| self.monitor_view(id, monitor)),
)
.into()
})
}
}

fn monitor_view<'a>(&self, id: &'a str, monitor: &'a MonitorState) -> Element<'a, AppMsg> {
Expand Down Expand Up @@ -244,20 +238,6 @@ impl AppState {
// }))
// .into()
// }

fn dark_mode_view(&self) -> Element<AppMsg> {
padded_control(
mouse_area(
row()
.align_y(Alignment::Center)
.push(text(fl!("dark_mode")))
.push(horizontal_space())
.push(toggler(self.theme_mode_config.is_dark).on_toggle(AppMsg::SetDarkMode)),
)
.on_press(AppMsg::SetDarkMode(!self.theme_mode_config.is_dark)),
)
.into()
}
}

fn brightness_icon(brightness: f32) -> icon::Handle {
Expand Down