update applets using latest libcosmic auto-sizing popups

This commit is contained in:
Ashley Wulber 2022-12-27 18:35:06 -05:00
parent a1aa87f5bd
commit 88b4a7d20b
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
13 changed files with 319 additions and 251 deletions

49
Cargo.lock generated
View file

@ -322,9 +322,9 @@ checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
[[package]]
name = "calloop"
version = "0.10.4"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19457a0da465234abd76134a5c2a910c14bd3c5558463e4396ab9a37a328e465"
checksum = "1a59225be45a478d772ce015d9743e49e92798ece9e34eda9a6aa2a6a7f40192"
dependencies = [
"log",
"nix 0.25.1",
@ -1421,8 +1421,9 @@ dependencies = [
[[package]]
name = "freedesktop-icons"
version = "0.2.1"
source = "git+https://github.com/wash2/freedestkop-icons#ac6343d76f1d2b3b666771b5ec0d22aa571a912e"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e31823094643eabe14030d2f1b3f0aa10164f27b1a31e2b938ffe8ea9c9fc91b"
dependencies = [
"dirs 4.0.0",
"once_cell",
@ -1995,7 +1996,7 @@ dependencies = [
[[package]]
name = "iced"
version = "0.6.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"iced_core",
"iced_futures",
@ -2012,7 +2013,7 @@ dependencies = [
[[package]]
name = "iced_core"
version = "0.6.2"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"bitflags",
"palette",
@ -2022,7 +2023,7 @@ dependencies = [
[[package]]
name = "iced_futures"
version = "0.5.1"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"futures",
"log",
@ -2034,7 +2035,7 @@ dependencies = [
[[package]]
name = "iced_glow"
version = "0.5.1"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"bytemuck",
"euclid",
@ -2049,7 +2050,7 @@ dependencies = [
[[package]]
name = "iced_graphics"
version = "0.5.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"bitflags",
"bytemuck",
@ -2069,7 +2070,7 @@ dependencies = [
[[package]]
name = "iced_lazy"
version = "0.3.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"iced_native",
"ouroboros 0.13.0",
@ -2078,7 +2079,7 @@ dependencies = [
[[package]]
name = "iced_native"
version = "0.7.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"iced_core",
"iced_futures",
@ -2092,7 +2093,7 @@ dependencies = [
[[package]]
name = "iced_sctk"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"enum-repr",
"futures",
@ -2111,7 +2112,7 @@ dependencies = [
[[package]]
name = "iced_style"
version = "0.5.1"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"iced_core",
"once_cell",
@ -2121,7 +2122,7 @@ dependencies = [
[[package]]
name = "iced_swbuf"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"cosmic-text",
"iced_graphics",
@ -2136,7 +2137,7 @@ dependencies = [
[[package]]
name = "iced_wgpu"
version = "0.7.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"bitflags",
"bytemuck",
@ -2326,7 +2327,7 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "libcosmic"
version = "0.1.0"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#55d00bd21a9ac69983666cd06b2c14a75a4e811f"
source = "git+https://github.com/pop-os/libcosmic/?branch=master#01701759c9224c94c340c81ad4f857ff8c7079ec"
dependencies = [
"apply",
"cosmic-panel-config",
@ -3179,9 +3180,9 @@ checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6"
[[package]]
name = "rangemap"
version = "1.1.0"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ed5f515fe4093fa60900ac1918c9ea73f18189114588ec9b99941e22cc2aedd"
checksum = "4fa20df61fa7daf0ecf0735b9841ced4a0d25962d1b1eb2dd28dcdd37bb688f2"
[[package]]
name = "raqote"
@ -3390,9 +3391,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "0.36.5"
version = "0.36.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588"
checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549"
dependencies = [
"bitflags",
"errno",
@ -3491,18 +3492,18 @@ checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"
[[package]]
name = "serde"
version = "1.0.151"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97fed41fc1a24994d044e6db6935e69511a1153b52c15eb42493b26fa87feba0"
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.151"
version = "1.0.152"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "255abe9a125a985c05190d687b320c12f9b1f0b99445e608c21ba0782c719ad8"
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
dependencies = [
"proc-macro2",
"quote",

View file

@ -23,7 +23,7 @@ log = "0.4"
tokio = { version = "1.17.0", features = ["sync", "rt", "rt-multi-thread", "macros", "process"] }
itertools = "*"
freedesktop-desktop-entry = "0.5.0"
freedesktop-icons = { git = "https://github.com/wash2/freedestkop-icons" }
freedesktop-icons = "0.2.2"
i18n-embed = { version = "0.13", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6"
rust-embed = "6.3"

View file

@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::ffi::OsStr;
use std::path::Path;
use std::path::PathBuf;
use crate::config;
@ -22,6 +22,7 @@ use cosmic::iced::widget::{column, row};
use cosmic::iced::{executor, window, Application, Command, Subscription};
use cosmic::iced_native::alignment::Horizontal;
use cosmic::iced_native::subscription::events_with;
use cosmic::iced_native::widget::vertical_space;
use cosmic::iced_style::application::{self, Appearance};
use cosmic::iced_style::Color;
use cosmic::theme::Button;
@ -35,8 +36,6 @@ use freedesktop_desktop_entry::DesktopEntry;
use iced::wayland::window::resize_window;
use iced::widget::container;
use iced::widget::horizontal_space;
use iced::widget::svg;
use iced::widget::Image;
use iced::Alignment;
use iced::Background;
use iced::Length;
@ -219,11 +218,11 @@ impl Application for CosmicAppList {
let new_id = window::Id::new(self.surface_id_ctr);
self.popup.replace(new_id);
toplevel_group.popup.replace(new_id);
let mut popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
(240, 240 + toplevel_group.toplevels.len() as u32 * 24),
None,
None,
None,
);
@ -399,23 +398,24 @@ impl Application for CosmicAppList {
desktop_info,
..
}| {
let icon = if desktop_info.icon.extension() == Some(&OsStr::new("svg")) {
let handle = svg::Handle::from_path(&desktop_info.icon);
svg::Svg::new(handle)
.width(Length::Units(self.applet_helper.suggested_size().0))
.height(Length::Units(self.applet_helper.suggested_size().0))
.into()
} else {
Image::new(&desktop_info.icon)
.width(Length::Units(self.applet_helper.suggested_size().0))
.height(Length::Units(self.applet_helper.suggested_size().0))
.into()
};
let cosmic_icon = cosmic::widget::icon(Path::new(&desktop_info.icon), self.applet_helper.suggested_size().0);
// let icon = if desktop_info.icon.extension() == Some(&OsStr::new("svg")) {
// svg::Handle::from_path(&desktop_info.icon);
// svg::Svg::new(handle)
// .width(Length::Units(self.applet_helper.suggested_size().0))
// .height(Length::Units(self.applet_helper.suggested_size().0))
// .into()
// } else {
// Image::new(&desktop_info.icon)
// .width(Length::Units(self.applet_helper.suggested_size().0))
// .height(Length::Units(self.applet_helper.suggested_size().0))
// .into()
// };
let dot_radius = 2;
let dots = (0..toplevels.len())
let mut dots = (0..toplevels.len())
.into_iter()
.map(|_| {
container(horizontal_space(Length::Units(0)))
container(vertical_space(Length::Units(0)))
.padding(dot_radius)
.style(<Self::Theme as container::StyleSheet>::Style::Custom(
|theme| container::Appearance {
@ -431,21 +431,21 @@ impl Application for CosmicAppList {
.into()
})
.collect_vec();
dots.push(vertical_space(Length::Units(4)).into());
let icon_wrapper = match &self.applet_helper.anchor {
PanelAnchor::Left => row(vec![column(dots).spacing(4).into(), icon])
PanelAnchor::Left => row(vec![column(dots).spacing(4).into(), cosmic_icon.into()])
.align_items(iced::Alignment::Center)
.spacing(4)
.into(),
PanelAnchor::Right => row(vec![icon, column(dots).spacing(4).into()])
PanelAnchor::Right => row(vec![cosmic_icon.into(), column(dots).spacing(4).into()])
.align_items(iced::Alignment::Center)
.spacing(4)
.into(),
PanelAnchor::Top => column(vec![row(dots).spacing(4).into(), icon])
PanelAnchor::Top => column(vec![row(dots).spacing(4).into(), cosmic_icon.into()])
.align_items(iced::Alignment::Center)
.spacing(4)
.into(),
PanelAnchor::Bottom => column(vec![icon, row(dots).spacing(4).into()])
PanelAnchor::Bottom => column(vec![cosmic_icon.into(), row(dots).spacing(4).into()])
.align_items(iced::Alignment::Center)
.spacing(4)
.into(),
@ -567,6 +567,15 @@ impl Application for CosmicAppList {
.on_press(Message::Quit(desktop_info.id.clone())),
)
}
// return Container::new(Container::new(content.width(Length::Shrink).height(Length::Shrink)).style(
// cosmic::Container::Custom(|theme| container::Appearance {
// text_color: Some(theme.cosmic().on_bg_color().into()),
// background: Some(theme.extended_palette().background.base.color.into()),
// border_radius: 12.0,
// border_width: 0.0,
// border_color: Color::TRANSPARENT,
// }),
// )).into();
return self.applet_helper.popup_container(content).into();
}
return horizontal_space(Length::Units(1)).into();

View file

@ -1,27 +1,24 @@
use cosmic::iced::wayland::SurfaceIdWrapper;
use cosmic::iced::widget;
use cosmic::iced_native::alignment::Horizontal;
use cosmic::theme::Svg;
use iced::widget::Space;
use cosmic::widget::{icon, toggler, horizontal_rule};
use cosmic::applet::CosmicAppletHelper;
use cosmic::widget::icon;
use cosmic::Renderer;
use cosmic::iced_native::window::Settings;
use cosmic::iced_style::application::{self, Appearance};
use cosmic::iced_style::svg;
use cosmic::theme::{self, Svg};
use cosmic::{iced_style, settings, Element, Theme};
use cosmic::iced::{
self,
executor,
widget::{button, column, row, text, slider},
self, executor,
widget::{button, column, row, slider, text},
window, Alignment, Application, Command, Length, Subscription,
};
use cosmic::iced_style::application::{self, Appearance};
use cosmic::{Element, Theme};
use iced::wayland::popup::{destroy_popup, get_popup};
use iced::Color;
use iced::widget::container;
use iced::Color;
mod pulse;
use crate::pulse::DeviceInfo;
@ -93,7 +90,7 @@ impl Application for Audio {
String::from("Audio")
}
fn theme(&self) -> Theme {
fn theme(&self) -> Theme {
self.theme
}
@ -114,12 +111,17 @@ impl Application for Audio {
if let Some(p) = self.popup.take() {
return destroy_popup(p);
} else {
self.id_ctr += 1;
self.id_ctr += 1;
let new_id = window::Id::new(self.id_ctr);
self.popup.replace(new_id);
let popup_settings =
self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (400, 300), None, None);
let popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
Some((400, 300)),
None,
None,
);
return get_popup(popup_settings);
}
}
@ -216,7 +218,7 @@ impl Application for Audio {
self.pulse_state = PulseState::Disconnected
}
},
Message::Ignore => {},
Message::Ignore => {}
};
Command::none()
@ -226,14 +228,14 @@ impl Application for Audio {
pulse::connect().map(Message::Pulse)
}
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
match id {
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button(
&self.icon_name,
)
.on_press(Message::TogglePopup)
.into(),
SurfaceIdWrapper::Window(_) => self
.applet_helper
.icon_button(&self.icon_name)
.on_press(Message::TogglePopup)
.into(),
SurfaceIdWrapper::Popup(_) => {
let out_f64 = VolumeLinear::from(
self.current_output
@ -251,19 +253,19 @@ impl Application for Audio {
.0 * 100.0;
let sink = row![
icon("status/audio-volume-high-symbolic", 24),
slider(0.0..=100.0, out_f64, Message::SetOutputVolume),
text(format!("{}%", out_f64.round()))
icon("audio-volume-high-symbolic", 64).width(Length::Units(24)).height(Length::Units(24)).style(Svg::SymbolicActive),
slider(0.0..=100.0, out_f64, Message::SetOutputVolume).width(Length::FillPortion(5)),
text(format!("{}%", out_f64.round())).width(Length::FillPortion(1)).horizontal_alignment(Horizontal::Right)
]
.spacing(10)
.padding(10);
.align_items(Alignment::Center);
let source = row![
icon("devices/audio-input-microphone-symbolic", 24),
slider(0.0..=100.0, in_f64, Message::SetInputVolume),
text(format!("{}%", in_f64.round()))
icon("audio-input-microphone-symbolic", 64).width(Length::Units(24)).height(Length::Units(24)).style(Svg::SymbolicActive),
slider(0.0..=100.0, in_f64, Message::SetInputVolume).width(Length::FillPortion(5)),
text(format!("{}%", in_f64.round())).width(Length::FillPortion(1)).horizontal_alignment(Horizontal::Right)
]
.spacing(10)
.padding(10);
.align_items(Alignment::Center);
// TODO change these from helper functions to iced components for improved reusability
let output_drop = revealer(
@ -304,11 +306,12 @@ impl Application for Audio {
.push(source)
.push(spacer())
.push(output_drop)
.push(input_drop);
.push(input_drop)
.padding(8);
self.applet_helper.popup_container(
container(content)
).into()
self.applet_helper
.popup_container(container(content))
.into()
}
}
}

View file

@ -9,18 +9,19 @@ use crate::upower_kbdbacklight::{
};
use cosmic::applet::CosmicAppletHelper;
use cosmic::iced::alignment::Horizontal;
use cosmic::iced::wayland::SurfaceIdWrapper;
use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
use cosmic::iced::wayland::SurfaceIdWrapper;
use cosmic::iced::{
executor,
widget::{button, column, row, text, slider},
widget::{button, column, row, slider, text},
window, Alignment, Application, Command, Length, Subscription,
};
use cosmic::iced_native::layout::Limits;
use cosmic::iced_style::application::{self, Appearance};
use cosmic::iced_style::{svg, Color};
use cosmic::theme::{self, Svg};
use cosmic::widget::{icon, toggler, horizontal_rule};
use cosmic::{iced_style, settings, Element, Theme};
use cosmic::widget::{horizontal_rule, icon, toggler};
use cosmic::{iced_style, Element, Theme};
use std::time::Duration;
use tokio::sync::mpsc::UnboundedSender;
@ -139,8 +140,14 @@ impl Application for CosmicBatteryApplet {
let new_id = window::Id::new(self.id_ctr);
self.popup.replace(new_id);
let popup_settings =
self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (400, 240), None, None);
let mut popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
None,
None,
None,
);
popup_settings.positioner.size_limits = Limits::NONE.max_width(400).min_width(300).min_height(200).max_height(1080);
return get_popup(popup_settings);
}
}
@ -176,11 +183,11 @@ impl Application for CosmicBatteryApplet {
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
match id {
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button(
&self.icon_name,
)
.on_press(Message::TogglePopup)
.into(),
SurfaceIdWrapper::Window(_) => self
.applet_helper
.icon_button(&self.icon_name)
.on_press(Message::TogglePopup)
.into(),
SurfaceIdWrapper::Popup(_) => {
let name = text(fl!("battery")).size(18);
let description = text(
@ -198,82 +205,82 @@ impl Application for CosmicBatteryApplet {
},
)
.size(12);
self.applet_helper.popup_container(
column![
row![
icon(&*self.icon_name, 24)
.style(Svg::Custom(|theme| {
svg::Appearance {
color: Some(theme.palette().text),
}
}))
.width(Length::Units(24))
.height(Length::Units(24)),
column![name, description]
self.applet_helper
.popup_container(
column![
row![
icon(&*self.icon_name, 24)
.style(Svg::Custom(|theme| {
svg::Appearance {
color: Some(theme.palette().text),
}
}))
.width(Length::Units(24))
.height(Length::Units(24)),
column![name, description]
]
.spacing(8)
.align_items(Alignment::Center),
horizontal_rule(1),
toggler(fl!("max-charge"), self.charging_limit, |_| {
Message::SetChargingLimit(!self.charging_limit)
}).width(Length::Fill),
horizontal_rule(1),
row![
icon("display-brightness-symbolic", 24)
.style(Svg::Custom(|theme| {
svg::Appearance {
color: Some(theme.palette().text),
}
}))
.width(Length::Units(24))
.height(Length::Units(24)),
slider(
0..=100,
(self.screen_brightness * 100.0) as i32,
Message::SetScreenBrightness
),
text(format!("{:.0}%", self.screen_brightness * 100.0))
.width(Length::Units(40))
.horizontal_alignment(Horizontal::Right)
]
.spacing(12),
row![
icon("keyboard-brightness-symbolic", 24)
.style(Svg::Custom(|theme| {
svg::Appearance {
color: Some(theme.palette().text),
}
}))
.width(Length::Units(24))
.height(Length::Units(24)),
slider(
0..=100,
(self.kbd_brightness * 100.0) as i32,
Message::SetKbdBrightness
),
text(format!("{:.0}%", self.kbd_brightness * 100.0))
.width(Length::Units(40))
.horizontal_alignment(Horizontal::Right)
]
.spacing(12),
button(
text(fl!("power-settings"))
.horizontal_alignment(Horizontal::Center)
.width(Length::Fill)
.style(theme::Text::Custom(|theme| {
let cosmic = theme.cosmic();
iced_style::text::Appearance {
color: Some(cosmic.accent.on.into()),
}
}))
)
.width(Length::Fill)
]
.spacing(8)
.align_items(Alignment::Center),
horizontal_rule(1),
// text{"Limit Battery Charging"},
toggler(fl!("max-charge"), self.charging_limit, |_| {
Message::SetChargingLimit(!self.charging_limit)
}),
horizontal_rule(1),
row![
icon("display-brightness-symbolic", 24)
.style(Svg::Custom(|theme| {
svg::Appearance {
color: Some(theme.palette().text),
}
}))
.width(Length::Units(24))
.height(Length::Units(24)),
slider(
0..=100,
(self.screen_brightness * 100.0) as i32,
Message::SetScreenBrightness
),
text(format!("{:.0}%", self.screen_brightness * 100.0))
.width(Length::Units(40))
.horizontal_alignment(Horizontal::Right)
]
.spacing(12),
row![
icon("keyboard-brightness-symbolic", 24)
.style(Svg::Custom(|theme| {
svg::Appearance {
color: Some(theme.palette().text),
}
}))
.width(Length::Units(24))
.height(Length::Units(24)),
slider(
0..=100,
(self.kbd_brightness * 100.0) as i32,
Message::SetKbdBrightness
),
text(format!("{:.0}%", self.kbd_brightness * 100.0))
.width(Length::Units(40))
.horizontal_alignment(Horizontal::Right)
]
.spacing(12),
button(
text(fl!("power-settings"))
.horizontal_alignment(Horizontal::Center)
.width(Length::Fill)
.style(theme::Text::Custom(|theme| {
let cosmic = theme.cosmic();
iced_style::text::Appearance {
color: Some(cosmic.accent.on.into()),
}
}))
)
.width(Length::Fill)
]
.spacing(4)
.padding(8),
)
.into()
.spacing(4)
.padding(8),
)
.into()
}
}
}

View file

@ -2,9 +2,7 @@ mod dbus;
mod graphics;
mod window;
use cosmic::{
iced::Application, applet::CosmicAppletHelper,
};
use cosmic::{applet::CosmicAppletHelper, iced::Application};
use window::*;
pub fn main() -> cosmic::iced::Result {

View file

@ -1,20 +1,20 @@
use crate::dbus::{self, PowerDaemonProxy};
use crate::graphics::{get_current_graphics, set_graphics, Graphics};
use cosmic::applet::{CosmicAppletHelper};
use cosmic::iced::wayland::SurfaceIdWrapper;
use cosmic::applet::CosmicAppletHelper;
use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
use cosmic::iced::wayland::SurfaceIdWrapper;
use cosmic::iced_native::alignment::Horizontal;
use cosmic::iced_style::Color;
use cosmic::iced_style::application::{self, Appearance};
use cosmic::iced_style::Color;
use cosmic::theme::Button;
use cosmic::{
applet::cosmic_panel_config::{PanelAnchor, PanelSize},
iced::widget::{column, radio, text},
iced::{self, Application, Command, Length},
iced_native::window,
theme::Theme,
widget::{horizontal_rule},
widget::horizontal_rule,
Element,
applet::cosmic_panel_config::{PanelAnchor, PanelSize}
};
use zbus::Connection;
@ -140,8 +140,13 @@ impl Application for Window {
|cur_graphics| Message::CurrentGraphics(cur_graphics.ok()),
));
}
let popup_settings =
self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (200, 240), None, None);
let popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
None,
None,
None,
);
commands.push(get_popup(popup_settings));
return Command::batch(commands);
}
@ -183,7 +188,9 @@ impl Application for Window {
fn view(&self, id: SurfaceIdWrapper) -> Element<Message> {
match id {
SurfaceIdWrapper::LayerSurface(_) => unimplemented!(),
SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button("input-gaming-symbolic")
SurfaceIdWrapper::Window(_) => self
.applet_helper
.icon_button("input-gaming-symbolic")
.on_press(Message::TogglePopup)
.style(Button::Text)
.into(),
@ -248,20 +255,21 @@ impl Application for Window {
.into()
}
};
self.applet_helper.popup_container(
column(vec![
text("Graphics Mode")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center)
.size(24)
.into(),
horizontal_rule(1).into(),
content,
])
.padding(4)
.spacing(4),
)
.into()
self.applet_helper
.popup_container(
column(vec![
text("Graphics Mode")
.width(Length::Fill)
.horizontal_alignment(Horizontal::Center)
.size(24)
.into(),
horizontal_rule(1).into(),
content,
])
.padding(8)
.spacing(4),
)
.into()
}
}
}

View file

@ -2,8 +2,12 @@ use cosmic::{
applet::CosmicAppletHelper,
iced::{
executor,
wayland::{
popup::{destroy_popup, get_popup},
SurfaceIdWrapper,
},
widget::{column, container, row, scrollable, text},
Alignment, Application, Color, Command, Length, Subscription, wayland::{popup::{destroy_popup, get_popup}, SurfaceIdWrapper},
Alignment, Application, Color, Command, Length, Subscription,
},
iced_native::window,
iced_style::{application, svg},
@ -44,26 +48,22 @@ struct CosmicNetworkApplet {
impl CosmicNetworkApplet {
fn update_icon_name(&mut self) {
self.icon_name = self
.active_conns
.iter()
.fold("network-offline-symbolic", |icon_name, conn| {
match (icon_name, conn) {
("network-offline-symbolic", ActiveConnectionInfo::WiFi { .. }) => {
"network-wireless-symbolic"
.active_conns
.iter()
.fold("network-offline-symbolic", |icon_name, conn| {
match (icon_name, conn) {
("network-offline-symbolic", ActiveConnectionInfo::WiFi { .. }) => {
"network-wireless-symbolic"
}
("network-offline-symbolic", ActiveConnectionInfo::Wired { .. })
| ("network-wireless-symbolic", ActiveConnectionInfo::Wired { .. }) => {
"network-wired-symbolic"
}
(_, ActiveConnectionInfo::Vpn { .. }) => "network-vpn-symbolic",
_ => icon_name,
}
(
"network-offline-symbolic",
ActiveConnectionInfo::Wired { .. },
)
| (
"network-wireless-symbolic",
ActiveConnectionInfo::Wired { .. },
) => "network-wired-symbolic",
(_, ActiveConnectionInfo::Vpn { .. }) => "network-vpn-symbolic",
_ => icon_name,
}
})
.to_string()
})
.to_string()
}
}
@ -112,7 +112,7 @@ impl Application for CosmicNetworkApplet {
let popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
(420, 600),
None,
None,
None,
);
@ -156,14 +156,20 @@ impl Application for CosmicNetworkApplet {
self.active_conns = conns;
self.update_icon_name();
}
NetworkManagerEvent::RequestResponse { wireless_access_points, active_conns, wifi_enabled, success, ..} => {
NetworkManagerEvent::RequestResponse {
wireless_access_points,
active_conns,
wifi_enabled,
success,
..
} => {
if success {
self.wireless_access_points = wireless_access_points;
self.active_conns = active_conns;
self.wifi = wifi_enabled;
self.update_icon_name();
}
},
}
},
Message::SelectWirelessAccessPoint(ssid) => {
if let Some(tx) = self.nm_sender.as_ref() {
@ -312,7 +318,7 @@ impl Application for CosmicNetworkApplet {
});
list_col = list_col.add(button);
}
content = content.push(scrollable(list_col).height(Length::Fill));
content = content.push(scrollable(list_col).height(Length::Units(300)));
}
self.applet_helper.popup_container(content).into()
}

View file

@ -14,10 +14,22 @@ pub async fn active_connections(
for connection in active_connections {
if connection.vpn().await.unwrap_or_default() {
let mut ip_addresses = Vec::new();
for address_data in connection.ip4_config().await?.address_data().await.unwrap_or_default() {
for address_data in connection
.ip4_config()
.await?
.address_data()
.await
.unwrap_or_default()
{
ip_addresses.push(IpAddr::V4(address_data.address));
}
for address_data in connection.ip6_config().await?.address_data().await.unwrap_or_default() {
for address_data in connection
.ip6_config()
.await?
.address_data()
.await
.unwrap_or_default()
{
ip_addresses.push(IpAddr::V6(address_data.address));
}
info.push(ActiveConnectionInfo::Vpn {
@ -27,13 +39,30 @@ pub async fn active_connections(
continue;
}
for device in connection.devices().await.unwrap_or_default() {
match device.downcast_to_device().await.ok().and_then(|inner| inner) {
match device
.downcast_to_device()
.await
.ok()
.and_then(|inner| inner)
{
Some(SpecificDevice::Wired(wired_device)) => {
let mut ip_addresses = Vec::new();
for address_data in device.ip4_config().await?.address_data().await.unwrap_or_default() {
for address_data in device
.ip4_config()
.await?
.address_data()
.await
.unwrap_or_default()
{
ip_addresses.push(IpAddr::V4(address_data.address));
}
for address_data in device.ip6_config().await?.address_data().await.unwrap_or_default() {
for address_data in device
.ip6_config()
.await?
.address_data()
.await
.unwrap_or_default()
{
ip_addresses.push(IpAddr::V6(address_data.address));
}
info.push(ActiveConnectionInfo::Wired {
@ -56,10 +85,22 @@ pub async fn active_connections(
}
Some(SpecificDevice::WireGuard(_)) => {
let mut ip_addresses = Vec::new();
for address_data in connection.ip4_config().await?.address_data().await.unwrap_or_default() {
for address_data in connection
.ip4_config()
.await?
.address_data()
.await
.unwrap_or_default()
{
ip_addresses.push(IpAddr::V4(address_data.address));
}
for address_data in connection.ip6_config().await?.address_data().await.unwrap_or_default() {
for address_data in connection
.ip6_config()
.await?
.address_data()
.await
.unwrap_or_default()
{
ip_addresses.push(IpAddr::V6(address_data.address));
}
info.push(ActiveConnectionInfo::Vpn {
@ -71,14 +112,12 @@ pub async fn active_connections(
}
}
}
info.sort_by(|a, b| {
let helper = |conn: &ActiveConnectionInfo| {
match conn {
ActiveConnectionInfo::Vpn { name, .. } => format!("0{name}"),
ActiveConnectionInfo::Wired { name, .. } => format!("1{name}"),
ActiveConnectionInfo::WiFi { name, .. } => format!("2{name}"),
}
let helper = |conn: &ActiveConnectionInfo| match conn {
ActiveConnectionInfo::Vpn { name, .. } => format!("0{name}"),
ActiveConnectionInfo::Wired { name, .. } => format!("1{name}"),
ActiveConnectionInfo::WiFi { name, .. } => format!("2{name}"),
};
helper(a).cmp(&helper(b))
});

View file

@ -95,7 +95,7 @@ impl Application for Notifications {
let popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
(400, 300),
None,
None,
None,
);

View file

@ -1,9 +1,8 @@
use std::process;
use cosmic::applet::CosmicAppletHelper;
use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
use cosmic::iced::wayland::SurfaceIdWrapper;
use cosmic::iced::wayland::popup::{get_popup, destroy_popup};
use cosmic::iced::widget::{self, Row};
use cosmic::iced_native::widget::Space;
use cosmic::widget::{horizontal_rule, icon};
@ -110,7 +109,7 @@ impl Application for Power {
let popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
(400, 300),
None,
None,
None,
);
@ -118,8 +117,8 @@ impl Application for Power {
}
}
Message::Settings => {
let _ = process::Command::new("cosmic-settings").spawn();
Command::none()
let _ = process::Command::new("cosmic-settings").spawn();
Command::none()
}
Message::Lock => Command::perform(lock(), Message::Zbus),
Message::LogOut => Command::perform(log_out(), Message::Zbus),
@ -145,8 +144,7 @@ impl Application for Power {
.on_press(Message::TogglePopup)
.into(),
SurfaceIdWrapper::Popup(_) => {
let settings = row_button(vec!["Settings...".into()])
.on_press(Message::Settings);
let settings = row_button(vec!["Settings...".into()]).on_press(Message::Settings);
let session = column![
row_button(vec![
@ -183,7 +181,8 @@ impl Application for Power {
.push(horizontal_rule(1))
.push(session)
.push(horizontal_rule(1))
.push(power);
.push(power)
.padding(8);
self.applet_helper.popup_container(content).into()
}
@ -208,10 +207,7 @@ fn row_button(mut content: Vec<Element<Message>>) -> widget::Button<Message, Ren
.style(theme::Button::Text)
}
fn power_buttons<'a>(
name: &'a str,
text: &'a str,
) -> widget::Button<'a, Message, Renderer> {
fn power_buttons<'a>(name: &'a str, text: &'a str) -> widget::Button<'a, Message, Renderer> {
button(
column![text_icon(name, 40), text]
.spacing(5)

View file

@ -120,7 +120,7 @@ impl Application for Time {
let popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
new_id,
(400, 300),
None,
Some(60),
None,
);
@ -166,7 +166,8 @@ impl Application for Time {
.align_items(Alignment::Start)
.spacing(12)
.padding([24, 0])
.push(text(calendar));
.push(text(calendar))
.padding(8);
self.applet_helper.popup_container(content).into()
}

View file

@ -1,21 +1,21 @@
use std::cmp::Ordering;
use calloop::channel::SyncSender;
use cosmic::applet::CosmicAppletHelper;
use cosmic::applet::cosmic_panel_config::PanelAnchor;
use cosmic::applet::CosmicAppletHelper;
use cosmic::iced::alignment::{Horizontal, Vertical};
use cosmic::iced::mouse::{self, ScrollDelta};
use cosmic::iced::wayland::actions::window::SctkWindowSettings;
use cosmic::iced::wayland::{window::resize_window, InitialSurface, SurfaceIdWrapper};
use cosmic::iced::widget::{column, container, row, text};
use cosmic::iced::{
executor, subscription, widget::button, window, Application, Command, Event::Mouse, Length,
Settings, Subscription,
};
use cosmic::iced_style::Color;
use cosmic::iced_style::application::{self, Appearance};
use cosmic::iced_style::Color;
use cosmic::theme::Button;
use cosmic::{Element, Theme};
use cosmic_protocols::workspace::v1::client::zcosmic_workspace_handle_v1;
use cosmic::iced::wayland::{SurfaceIdWrapper, InitialSurface, window::resize_window};
use std::cmp::Ordering;
use wayland_backend::client::ObjectId;
use crate::config;