Implement suspend with logind
This commit is contained in:
parent
5d0999df83
commit
13e3dcd911
5 changed files with 58 additions and 1 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
|
@ -800,11 +800,13 @@ dependencies = [
|
||||||
"greetd_ipc",
|
"greetd_ipc",
|
||||||
"libcosmic",
|
"libcosmic",
|
||||||
"log",
|
"log",
|
||||||
|
"logind-zbus",
|
||||||
"pam-client",
|
"pam-client",
|
||||||
"pwd",
|
"pwd",
|
||||||
"shlex",
|
"shlex",
|
||||||
"tokio",
|
"tokio",
|
||||||
"wayland-client 0.31.1",
|
"wayland-client 0.31.1",
|
||||||
|
"zbus",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -2376,6 +2378,16 @@ version = "0.4.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "logind-zbus"
|
||||||
|
version = "3.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c07a2542f6e91ea92780158654852190edb2ba0b232d9d00d649d0c691cb7eb3"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"zbus",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lru"
|
name = "lru"
|
||||||
version = "0.11.1"
|
version = "0.11.1"
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,12 @@ chrono = "0.4.31"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
freedesktop_entry_parser = "1.3.0"
|
freedesktop_entry_parser = "1.3.0"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
|
logind-zbus = { version = "3.1.2", optional = true }
|
||||||
pam-client = "0.5.0"
|
pam-client = "0.5.0"
|
||||||
pwd = "1.4.0"
|
pwd = "1.4.0"
|
||||||
shlex = "1.2.0"
|
shlex = "1.2.0"
|
||||||
wayland-client = "0.31.1"
|
wayland-client = "0.31.1"
|
||||||
|
zbus = { version = "3.14.1", optional = true }
|
||||||
|
|
||||||
[dependencies.cosmic-bg-config]
|
[dependencies.cosmic-bg-config]
|
||||||
git = "https://github.com/pop-os/cosmic-bg"
|
git = "https://github.com/pop-os/cosmic-bg"
|
||||||
|
|
@ -31,3 +33,7 @@ features = ["tokio", "wayland"]
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
version = "1.33.0"
|
version = "1.33.0"
|
||||||
features = ["full"]
|
features = ["full"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["logind"]
|
||||||
|
logind = ["logind-zbus", "zbus"]
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,7 @@ pub enum Message {
|
||||||
BackgroundState(cosmic_bg_config::state::State),
|
BackgroundState(cosmic_bg_config::state::State),
|
||||||
Prompt(String, bool, Option<String>),
|
Prompt(String, bool, Option<String>),
|
||||||
Submit,
|
Submit,
|
||||||
|
Suspend,
|
||||||
Error(String),
|
Error(String),
|
||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
|
@ -422,6 +423,21 @@ impl cosmic::Application for App {
|
||||||
},
|
},
|
||||||
None => log::warn!("tried to submit without prompt"),
|
None => log::warn!("tried to submit without prompt"),
|
||||||
},
|
},
|
||||||
|
Message::Suspend => {
|
||||||
|
#[cfg(feature = "logind")]
|
||||||
|
return Command::perform(
|
||||||
|
async move {
|
||||||
|
match crate::logind::suspend().await {
|
||||||
|
Ok(()) => message::none(),
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("failed to suspend: {:?}", err);
|
||||||
|
message::app(Message::Error(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|x| x,
|
||||||
|
);
|
||||||
|
}
|
||||||
Message::Error(error) => {
|
Message::Error(error) => {
|
||||||
self.error_opt = Some(error);
|
self.error_opt = Some(error);
|
||||||
}
|
}
|
||||||
|
|
@ -499,7 +515,7 @@ impl cosmic::Application for App {
|
||||||
.on_press(Message::None),
|
.on_press(Message::None),
|
||||||
widget::button(widget::icon::from_name("system-suspend-symbolic"))
|
widget::button(widget::icon::from_name("system-suspend-symbolic"))
|
||||||
.padding(12.0)
|
.padding(12.0)
|
||||||
.on_press(Message::None),
|
.on_press(Message::Suspend),
|
||||||
]
|
]
|
||||||
.padding([16.0, 0.0, 0.0, 0.0])
|
.padding([16.0, 0.0, 0.0, 0.0])
|
||||||
.spacing(8.0);
|
.spacing(8.0);
|
||||||
|
|
|
||||||
20
src/logind.rs
Normal file
20
src/logind.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
use logind_zbus::manager::ManagerProxy;
|
||||||
|
use zbus::{Connection, Result};
|
||||||
|
|
||||||
|
pub async fn power_off() -> Result<()> {
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
let manager = ManagerProxy::new(&connection).await?;
|
||||||
|
manager.reboot(false).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn reboot() -> Result<()> {
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
let manager = ManagerProxy::new(&connection).await?;
|
||||||
|
manager.reboot(false).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn suspend() -> Result<()> {
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
let manager = ManagerProxy::new(&connection).await?;
|
||||||
|
manager.suspend(false).await
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,9 @@ mod greeter;
|
||||||
mod image_container;
|
mod image_container;
|
||||||
mod locker;
|
mod locker;
|
||||||
|
|
||||||
|
#[cfg(feature = "logind")]
|
||||||
|
mod logind;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue