helpers
This commit is contained in:
parent
f9c47cf479
commit
9260ee87e1
7 changed files with 112 additions and 66 deletions
|
|
@ -7,10 +7,11 @@ edition = "2021"
|
||||||
name = "cosmic"
|
name = "cosmic"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["wayland"]
|
default = ["wgpu"]
|
||||||
debug = ["iced/debug"]
|
debug = ["iced/debug"]
|
||||||
wayland = ["iced/wayland"]
|
wayland = ["iced/wayland"]
|
||||||
wgpu = ["iced/wgpu"]
|
wgpu = ["iced/wgpu"]
|
||||||
|
applet = ["cosmic-panel-config", "sctk"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
freedesktop-icons = "0.2.1"
|
freedesktop-icons = "0.2.1"
|
||||||
|
|
@ -18,6 +19,8 @@ apply = "0.3.0"
|
||||||
derive_setters = "0.1.5"
|
derive_setters = "0.1.5"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
palette = "0.6.1"
|
palette = "0.6.1"
|
||||||
|
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false, optional = true }
|
||||||
|
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", optional = true }
|
||||||
|
|
||||||
[dependencies.cosmic-theme]
|
[dependencies.cosmic-theme]
|
||||||
git = "https://github.com/pop-os/cosmic-theme.git"
|
git = "https://github.com/pop-os/cosmic-theme.git"
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
zbus = "3.4"
|
zbus = "3.4"
|
||||||
libcosmic = { path = "../..", default-features = false, features = ["debug", "wayland"] }
|
libcosmic = { path = "../..", default-features = false, features = ["debug", "wayland", "applet"] }
|
||||||
# cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel" }
|
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false }
|
||||||
cosmic-panel-config = { path = "../../../cosmic-panel/cosmic-panel-config", default-features = false }
|
|
||||||
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
iced_sctk = { git = "https://github.com/pop-os/iced-sctk" }
|
||||||
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit" }
|
sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit" }
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@
|
||||||
|
|
||||||
use zbus::{dbus_proxy, Connection};
|
use zbus::{dbus_proxy, Connection};
|
||||||
|
|
||||||
#[dbus_proxy(interface = "com.system76.PowerDaemon", default_path = "/com/system76/PowerDaemon")]
|
#[dbus_proxy(
|
||||||
|
interface = "com.system76.PowerDaemon",
|
||||||
|
default_path = "/com/system76/PowerDaemon"
|
||||||
|
)]
|
||||||
trait PowerDaemon {
|
trait PowerDaemon {
|
||||||
/// Balanced method
|
/// Balanced method
|
||||||
fn balanced(&self) -> zbus::Result<()>;
|
fn balanced(&self) -> zbus::Result<()>;
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,17 @@
|
||||||
use crate::dbus::{self, PowerDaemonProxy};
|
use crate::dbus::{self, PowerDaemonProxy};
|
||||||
use crate::graphics::{get_current_graphics, Graphics, set_graphics};
|
use crate::graphics::{get_current_graphics, set_graphics, Graphics};
|
||||||
use cosmic::widget::{expander, icon, nav_bar, nav_bar_page, nav_bar_section};
|
use cosmic::applet::{get_popup_settings, icon_button};
|
||||||
|
use cosmic::separator;
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::widget::{
|
iced::widget::{column, radio, text},
|
||||||
checkbox, column, container, horizontal_space, pick_list, progress_bar, radio, row, slider,
|
iced::{self, Application, Command, Length},
|
||||||
text,
|
|
||||||
},
|
|
||||||
iced::{self, Alignment, Application, Color, Command, Length},
|
|
||||||
iced_lazy::responsive,
|
|
||||||
iced_native::window,
|
iced_native::window,
|
||||||
iced_winit::window::{drag, maximize, minimize},
|
|
||||||
list_view, list_view_item, list_view_row, list_view_section, scrollable,
|
|
||||||
theme::{self, Theme},
|
theme::{self, Theme},
|
||||||
widget::{button, header_bar, list_box, list_row, list_view::*, toggler},
|
|
||||||
Element,
|
Element,
|
||||||
};
|
};
|
||||||
use cosmic::{iced_native, separator};
|
use cosmic_panel_config::{PanelAnchor, PanelSize};
|
||||||
use cosmic_panel_config::{PanelSize, PanelAnchor};
|
|
||||||
use iced_sctk::alignment::Horizontal;
|
use iced_sctk::alignment::Horizontal;
|
||||||
use iced_sctk::command::platform_specific::wayland::popup::{SctkPopupSettings, SctkPositioner};
|
|
||||||
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
use iced_sctk::commands::popup::{destroy_popup, get_popup};
|
||||||
use iced_sctk::{Point, Rectangle, Size};
|
|
||||||
use sctk::reexports::protocols::xdg::shell::client::xdg_positioner::{Anchor, Gravity};
|
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
#[derive(Default, Clone, Copy)]
|
#[derive(Default, Clone, Copy)]
|
||||||
|
|
@ -74,12 +64,12 @@ impl Application for Window {
|
||||||
.unwrap_or(16);
|
.unwrap_or(16);
|
||||||
window.icon_size = pixels;
|
window.icon_size = pixels;
|
||||||
window.anchor = std::env::var("COSMIC_PANEL_ANCHOR")
|
window.anchor = std::env::var("COSMIC_PANEL_ANCHOR")
|
||||||
.ok()
|
.ok()
|
||||||
.map(|size| match size.parse::<PanelAnchor>() {
|
.map(|size| match size.parse::<PanelAnchor>() {
|
||||||
Ok(p) => p,
|
Ok(p) => p,
|
||||||
Err(_) => PanelAnchor::Top,
|
Err(_) => PanelAnchor::Top,
|
||||||
})
|
})
|
||||||
.unwrap_or(PanelAnchor::Top);
|
.unwrap_or(PanelAnchor::Top);
|
||||||
(
|
(
|
||||||
window,
|
window,
|
||||||
Command::perform(dbus::init(), |dbus_init| Message::DBusInit(dbus_init)),
|
Command::perform(dbus::init(), |dbus_init| Message::DBusInit(dbus_init)),
|
||||||
|
|
@ -96,9 +86,12 @@ impl Application for Window {
|
||||||
dbg!(new_graphics_mode);
|
dbg!(new_graphics_mode);
|
||||||
if let Some((_, proxy)) = self.dbus.as_ref() {
|
if let Some((_, proxy)) = self.dbus.as_ref() {
|
||||||
self.state = State::SettingGraphicsMode(new_graphics_mode);
|
self.state = State::SettingGraphicsMode(new_graphics_mode);
|
||||||
return Command::perform(set_graphics(proxy.clone(), new_graphics_mode), move |success| {
|
return Command::perform(
|
||||||
Message::AppliedGraphicsMode(success.ok().map(|_| new_graphics_mode))
|
set_graphics(proxy.clone(), new_graphics_mode),
|
||||||
},);
|
move |success| {
|
||||||
|
Message::AppliedGraphicsMode(success.ok().map(|_| new_graphics_mode))
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::AppliedGraphicsMode(g) => {
|
Message::AppliedGraphicsMode(g) => {
|
||||||
|
|
@ -107,7 +100,7 @@ impl Application for Window {
|
||||||
self.graphics_mode.replace(g);
|
self.graphics_mode.replace(g);
|
||||||
self.state = State::SelectGraphicsMode;
|
self.state = State::SelectGraphicsMode;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Message::TogglePopup => {
|
Message::TogglePopup => {
|
||||||
if let Some(p) = self.popup.take() {
|
if let Some(p) = self.popup.take() {
|
||||||
return destroy_popup(p);
|
return destroy_popup(p);
|
||||||
|
|
@ -122,31 +115,8 @@ impl Application for Window {
|
||||||
|cur_graphics| Message::CurrentGraphics(cur_graphics.ok()),
|
|cur_graphics| Message::CurrentGraphics(cur_graphics.ok()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let (anchor, gravity) = match self.anchor {
|
let popup_settings = get_popup_settings(window::Id::new(0), new_id, None, None);
|
||||||
PanelAnchor::Left => (Anchor::Right, Gravity::Right),
|
commands.push(get_popup(popup_settings));
|
||||||
PanelAnchor::Right => (Anchor::Left, Gravity::Left),
|
|
||||||
PanelAnchor::Top => (Anchor::Bottom, Gravity::Bottom),
|
|
||||||
PanelAnchor::Bottom => (Anchor::Top, Gravity::Top),
|
|
||||||
};
|
|
||||||
commands.push(Command::batch(vec![get_popup(SctkPopupSettings {
|
|
||||||
parent: window::Id::new(0),
|
|
||||||
id: new_id,
|
|
||||||
positioner: SctkPositioner {
|
|
||||||
anchor,
|
|
||||||
gravity,
|
|
||||||
size: (200, 200),
|
|
||||||
anchor_rect: Rectangle {
|
|
||||||
x: 0,
|
|
||||||
y: 0,
|
|
||||||
width: 32 + self.icon_size as i32,
|
|
||||||
height: 16 + self.icon_size as i32,
|
|
||||||
},
|
|
||||||
reactive: true,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
parent_size: None,
|
|
||||||
grab: true,
|
|
||||||
})]));
|
|
||||||
return Command::batch(commands);
|
return Command::batch(commands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -160,12 +130,13 @@ impl Application for Window {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
dbg!(err);
|
dbg!(err);
|
||||||
None
|
None
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Message::CurrentGraphics(g) => {
|
Message::CurrentGraphics(g) => {
|
||||||
|
dbg!(g);
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
self.graphics_mode.replace(g);
|
self.graphics_mode.replace(g);
|
||||||
}
|
}
|
||||||
|
|
@ -216,10 +187,14 @@ impl Application for Window {
|
||||||
Graphics::Nvidia => "nvidia",
|
Graphics::Nvidia => "nvidia",
|
||||||
Graphics::Compute => "compute",
|
Graphics::Compute => "compute",
|
||||||
};
|
};
|
||||||
column(vec![
|
column(vec![text(format!(
|
||||||
text(format!("Setting graphics mode to {graphics_str}...")).width(Length::Fill).horizontal_alignment(Horizontal::Center).into()
|
"Setting graphics mode to {graphics_str}..."
|
||||||
]).into()
|
))
|
||||||
},
|
.width(Length::Fill)
|
||||||
|
.horizontal_alignment(Horizontal::Center)
|
||||||
|
.into()])
|
||||||
|
.into()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
column(vec![
|
column(vec![
|
||||||
text("Graphics Mode")
|
text("Graphics Mode")
|
||||||
|
|
@ -251,12 +226,11 @@ impl Application for Window {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view_window(&self, id: window::Id) -> Element<Message> {
|
fn view_window(&self, _: window::Id) -> Element<Message> {
|
||||||
// TODO use panel config crate after resolving version mismatch
|
// TODO use panel config crate after resolving version mismatch
|
||||||
|
|
||||||
button!(icon("input-gaming-symbolic", self.icon_size).style(theme::Svg::Accent))
|
let btn = icon_button().on_press(Message::TogglePopup);
|
||||||
.on_press(Message::TogglePopup)
|
btn.into()
|
||||||
.into()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_exit(&self) -> bool {
|
fn should_exit(&self) -> bool {
|
||||||
|
|
|
||||||
65
src/applet/mod.rs
Normal file
65
src/applet/mod.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
use cosmic_panel_config::{PanelSize, PanelAnchor};
|
||||||
|
use iced::{widget::Button, Rectangle};
|
||||||
|
use iced_native::{command::platform_specific::wayland::popup::{SctkPopupSettings, SctkPositioner}};
|
||||||
|
use sctk::reexports::protocols::xdg::shell::client::xdg_positioner::{Anchor, Gravity};
|
||||||
|
|
||||||
|
use crate::{button, widget::icon};
|
||||||
|
|
||||||
|
pub fn icon_button<'a, M: 'a, Renderer>() -> Button<'a, M, Renderer>
|
||||||
|
where
|
||||||
|
Renderer::Theme: iced_native::svg::StyleSheet + iced_style::button::StyleSheet,
|
||||||
|
Renderer: iced_native::Renderer + iced_native::svg::Renderer + 'a,
|
||||||
|
{
|
||||||
|
let pixels = std::env::var("COSMIC_PANEL_SIZE")
|
||||||
|
.ok()
|
||||||
|
.and_then(|size| match size.parse::<PanelSize>() {
|
||||||
|
Ok(PanelSize::XL) => Some(64),
|
||||||
|
Ok(PanelSize::L) => Some(36),
|
||||||
|
Ok(PanelSize::M) => Some(24),
|
||||||
|
Ok(PanelSize::S) => Some(16),
|
||||||
|
Ok(PanelSize::XS) => Some(12),
|
||||||
|
Err(_) => Some(12),
|
||||||
|
})
|
||||||
|
.unwrap_or(16);
|
||||||
|
button!(icon("input-gaming-symbolic", pixels))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_popup_settings(parent: iced_native::window::Id, id: iced_native::window::Id, width_padding: Option<i32>, height_padding: Option<i32>) -> SctkPopupSettings {
|
||||||
|
let anchor = std::env::var("COSMIC_PANEL_ANCHOR")
|
||||||
|
.ok()
|
||||||
|
.map(|size| match size.parse::<PanelAnchor>() {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(_) => PanelAnchor::Top,
|
||||||
|
})
|
||||||
|
.unwrap_or(PanelAnchor::Top);
|
||||||
|
let pixels = std::env::var("COSMIC_PANEL_SIZE")
|
||||||
|
.ok()
|
||||||
|
.and_then(|size| match size.parse::<PanelSize>() {
|
||||||
|
Ok(PanelSize::XL) => Some(64),
|
||||||
|
Ok(PanelSize::L) => Some(36),
|
||||||
|
Ok(PanelSize::M) => Some(24),
|
||||||
|
Ok(PanelSize::S) => Some(16),
|
||||||
|
Ok(PanelSize::XS) => Some(12),
|
||||||
|
Err(_) => Some(12),
|
||||||
|
})
|
||||||
|
.unwrap_or(16);
|
||||||
|
let (anchor, gravity) = match anchor {
|
||||||
|
PanelAnchor::Left => (Anchor::Right, Gravity::Right),
|
||||||
|
PanelAnchor::Right => (Anchor::Left, Gravity::Left),
|
||||||
|
PanelAnchor::Top => (Anchor::Bottom, Gravity::Bottom),
|
||||||
|
PanelAnchor::Bottom => (Anchor::Top, Gravity::Top),
|
||||||
|
};
|
||||||
|
SctkPopupSettings { parent, id, positioner: SctkPositioner {
|
||||||
|
anchor,
|
||||||
|
gravity,
|
||||||
|
size: (200, 200),
|
||||||
|
anchor_rect: Rectangle {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: width_padding.unwrap_or(16) * 2 + pixels as i32,
|
||||||
|
height: height_padding.unwrap_or(8) * 2 + pixels as i32,
|
||||||
|
},
|
||||||
|
reactive: true,
|
||||||
|
..Default::default()
|
||||||
|
}, parent_size: None, grab: true }
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,8 @@ pub use iced_native;
|
||||||
pub use iced_style;
|
pub use iced_style;
|
||||||
pub use iced_winit;
|
pub use iced_winit;
|
||||||
|
|
||||||
|
#[cfg(feature = "applet")]
|
||||||
|
pub mod applet;
|
||||||
pub mod font;
|
pub mod font;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
pub mod widget;
|
pub mod widget;
|
||||||
|
|
|
||||||
|
|
@ -429,7 +429,7 @@ impl pick_list::StyleSheet for Theme {
|
||||||
impl radio::StyleSheet for Theme {
|
impl radio::StyleSheet for Theme {
|
||||||
type Style = ();
|
type Style = ();
|
||||||
|
|
||||||
fn active(&self, _style: &Self::Style, is_checked: bool) -> radio::Appearance {
|
fn active(&self, _style: &Self::Style, _is_checked: bool) -> radio::Appearance {
|
||||||
let palette = self.extended_palette();
|
let palette = self.extended_palette();
|
||||||
|
|
||||||
radio::Appearance {
|
radio::Appearance {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue