Locking the screen now works.
This commit is contained in:
parent
1f65d44998
commit
dc92340774
3 changed files with 51 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -251,6 +251,7 @@ dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
"logind-zbus",
|
"logind-zbus",
|
||||||
|
"nix 0.23.1",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"relm4-macros",
|
"relm4-macros",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ license = "LGPL-3.0-or-later"
|
||||||
futures-util = "0.3.21"
|
futures-util = "0.3.21"
|
||||||
gtk4 = "0.4.6"
|
gtk4 = "0.4.6"
|
||||||
logind-zbus = "3.0.1"
|
logind-zbus = "3.0.1"
|
||||||
|
nix = "0.23.1"
|
||||||
once_cell = "1.9.0"
|
once_cell = "1.9.0"
|
||||||
relm4-macros = "0.4.1"
|
relm4-macros = "0.4.1"
|
||||||
tokio = { version = "1.15.0", features = ["full"] }
|
tokio = { version = "1.15.0", features = ["full"] }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,45 @@
|
||||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
use crate::RT;
|
||||||
use gtk4::{prelude::*, Align, Button, Image, Label, Orientation};
|
use gtk4::{prelude::*, Align, Button, Image, Label, Orientation};
|
||||||
|
use logind_zbus::{
|
||||||
|
manager::ManagerProxy,
|
||||||
|
session::{SessionProxy, SessionType},
|
||||||
|
user::UserProxy,
|
||||||
|
};
|
||||||
|
use nix::unistd::getuid;
|
||||||
|
use zbus::Connection;
|
||||||
|
|
||||||
|
async fn lock_screen() -> zbus::Result<()> {
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||||
|
// Get the session this current process is running in
|
||||||
|
let our_uid = getuid().as_raw() as u32;
|
||||||
|
let user_path = manager_proxy.get_user(our_uid).await?;
|
||||||
|
let user = UserProxy::builder(&connection)
|
||||||
|
.path(user_path)?
|
||||||
|
.build()
|
||||||
|
.await?;
|
||||||
|
// Lock all non-TTY sessions of this user
|
||||||
|
let sessions = user.sessions().await?;
|
||||||
|
for (_, session_path) in sessions {
|
||||||
|
let session = SessionProxy::builder(&connection)
|
||||||
|
.path(session_path)?
|
||||||
|
.build()
|
||||||
|
.await?;
|
||||||
|
if session.type_().await? != SessionType::TTY {
|
||||||
|
session.lock().await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn log_out() -> zbus::Result<()> {
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
let manager_proxy = ManagerProxy::new(&connection).await?;
|
||||||
|
// TODO: figure out what function logs the current user out
|
||||||
|
manager_proxy.lock_sessions().await
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build() -> gtk4::Box {
|
pub fn build() -> gtk4::Box {
|
||||||
view! {
|
view! {
|
||||||
|
|
@ -45,5 +84,15 @@ pub fn build() -> gtk4::Box {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lock_screen_button.connect_clicked(|_| {
|
||||||
|
RT.spawn(async move {
|
||||||
|
lock_screen().await.expect("failed to lock screen");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
log_out_button.connect_clicked(|_| {
|
||||||
|
RT.spawn(async move {
|
||||||
|
log_out().await.expect("failed to log out");
|
||||||
|
});
|
||||||
|
});
|
||||||
inner_box
|
inner_box
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue