power: Use libcosmic-applet
This commit is contained in:
parent
b8bea240a8
commit
f8e7685939
3 changed files with 31 additions and 76 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -411,9 +411,9 @@ dependencies = [
|
||||||
name = "cosmic-applet-power"
|
name = "cosmic-applet-power"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cosmic-panel-config",
|
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
|
"libcosmic-applet",
|
||||||
"logind-zbus",
|
"logind-zbus",
|
||||||
"nix 0.24.1",
|
"nix 0.24.1",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ license = "GPL-3.0-or-later"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures-util = "0.3.21"
|
futures-util = "0.3.21"
|
||||||
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" }
|
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" }
|
||||||
|
libcosmic-applet = { path = "../../libcosmic-applet" }
|
||||||
logind-zbus = "3.0.1"
|
logind-zbus = "3.0.1"
|
||||||
nix = "0.24.1"
|
nix = "0.24.1"
|
||||||
once_cell = "1.9.0"
|
once_cell = "1.9.0"
|
||||||
relm4-macros = { git = "https://github.com/Relm4/Relm4.git", branch = "next" }
|
relm4-macros = { git = "https://github.com/Relm4/Relm4.git", branch = "next" }
|
||||||
tokio = { version = "1.15.0", features = ["full"] }
|
tokio = { version = "1.15.0", features = ["full"] }
|
||||||
zbus = "2.0.1"
|
zbus = "2.0.1"
|
||||||
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"]}
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ extern crate relm4_macros;
|
||||||
pub mod session_manager;
|
pub mod session_manager;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
|
|
||||||
use cosmic_panel_config::config::CosmicPanelConfig;
|
use gtk4::{gio::ApplicationFlags, prelude::*, Align, Button, Label, Orientation, Separator};
|
||||||
use gtk4::{gio::ApplicationFlags, glib, prelude::*, Align, Button, Label, Orientation, Separator};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
@ -24,81 +23,37 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_ui(application: >k4::Application) {
|
fn build_ui(application: >k4::Application) {
|
||||||
let provider = gtk4::CssProvider::new();
|
|
||||||
provider.load_from_data(include_bytes!("style.css"));
|
|
||||||
gtk4::StyleContext::add_provider_for_display(
|
|
||||||
>k4::gdk::Display::default().expect("Could not connect to a display."),
|
|
||||||
&provider,
|
|
||||||
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
|
||||||
);
|
|
||||||
|
|
||||||
let window = gtk4::ApplicationWindow::builder()
|
|
||||||
.application(application)
|
|
||||||
.title("COSMIC Power Applet")
|
|
||||||
.decorated(false)
|
|
||||||
.resizable(false)
|
|
||||||
.width_request(1)
|
|
||||||
.height_request(1)
|
|
||||||
.css_classes(vec!["root_window".to_string()])
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let config = CosmicPanelConfig::load_from_env().unwrap_or_default();
|
|
||||||
let popover = gtk4::builders::PopoverBuilder::new()
|
|
||||||
.autohide(true)
|
|
||||||
.has_arrow(false)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let button = gtk4::Button::new();
|
|
||||||
button.add_css_class("panel_icon");
|
|
||||||
button.connect_clicked(glib::clone!(@weak popover => move |_| {
|
|
||||||
popover.show();
|
|
||||||
}));
|
|
||||||
|
|
||||||
// TODO cleanup
|
|
||||||
// TODO adjust battery icon based on charge
|
|
||||||
let image = gtk4::Image::from_icon_name("system-shutdown-symbolic");
|
|
||||||
image.add_css_class("panel_icon");
|
|
||||||
image.set_pixel_size(config.get_applet_icon_size().try_into().unwrap());
|
|
||||||
view! {
|
view! {
|
||||||
icon_box = gtk4::Box {
|
window = libcosmic_applet::Applet {
|
||||||
set_orientation: Orientation::Vertical,
|
set_title: Some("COSMIC Power Applet"),
|
||||||
set_spacing: 0,
|
set_application: Some(application),
|
||||||
add_css_class: "icon_box",
|
// TODO adjust battery icon based on charge
|
||||||
}
|
set_button_icon_name: "system-shutdown-symbolic",
|
||||||
}
|
#[wrap(Some)]
|
||||||
button.set_child(Some(&image));
|
set_popover_child: main_box = >k4::Box {
|
||||||
|
set_orientation: Orientation::Vertical,
|
||||||
let session_section = ui::session::build();
|
set_spacing: 10,
|
||||||
let system_section = ui::system::build();
|
set_margin_top: 20,
|
||||||
view! {
|
set_margin_bottom: 20,
|
||||||
main_box = gtk4::Box {
|
set_margin_start: 24,
|
||||||
set_orientation: Orientation::Vertical,
|
set_margin_end: 24,
|
||||||
set_spacing: 10,
|
append: settings_button = &Button {
|
||||||
set_margin_top: 20,
|
#[wrap(Some)]
|
||||||
set_margin_bottom: 20,
|
set_child = &Label {
|
||||||
set_margin_start: 24,
|
set_label: "Settings...",
|
||||||
set_margin_end: 24,
|
set_halign: Align::Start,
|
||||||
append: settings_button = &Button {
|
set_hexpand: true
|
||||||
#[wrap(Some)]
|
},
|
||||||
set_child = &Label {
|
connect_clicked => move |_| {
|
||||||
set_label: "Settings...",
|
let _ = Command::new("cosmic-settings").spawn();
|
||||||
set_halign: Align::Start,
|
}
|
||||||
set_hexpand: true
|
|
||||||
},
|
},
|
||||||
connect_clicked => move |_| {
|
append = &Separator {},
|
||||||
let _ = Command::new("cosmic-settings").spawn();
|
append: &ui::session::build(),
|
||||||
}
|
append: second_separator = &Separator {},
|
||||||
},
|
append: &ui::system::build(),
|
||||||
append = &Separator {},
|
}
|
||||||
append: &session_section,
|
|
||||||
append: second_separator = &Separator {},
|
|
||||||
append: &system_section
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
popover.set_child(Some(&main_box));
|
|
||||||
|
|
||||||
icon_box.append(&button);
|
|
||||||
icon_box.append(&popover);
|
|
||||||
window.set_child(Some(&icon_box));
|
|
||||||
window.show();
|
window.show();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue