mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Buildup of logind dbus methods
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -523,6 +523,18 @@ dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "logind-zbus"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"zbus",
|
||||
"zbus_macros",
|
||||
"zvariant",
|
||||
"zvariant_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "loom"
|
||||
version = "0.4.0"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[workspace]
|
||||
members = ["asusctl", "asus-notify", "daemon", "rog-types", "rog-dbus"]
|
||||
members = ["asusctl", "asus-notify", "daemon", "rog-types", "rog-dbus", "logind-zbus"]
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
@@ -382,6 +382,15 @@ impl CtrlGraphics {
|
||||
return Err(GfxError::DisplayManagerTimeout(state.into()).into());
|
||||
}
|
||||
|
||||
/// Write the config changes and add/remove drivers and devices depending
|
||||
/// on selected mode:
|
||||
///
|
||||
/// Tasks:
|
||||
/// - write xorg config
|
||||
/// - write modprobe config
|
||||
/// - rescan for devices
|
||||
/// + add drivers
|
||||
/// + or remove drivers and devices
|
||||
pub fn do_vendor_tasks(
|
||||
vendor: GfxVendors,
|
||||
devices: &[GraphicsDevice],
|
||||
@@ -416,7 +425,7 @@ impl CtrlGraphics {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Spools until all user sessions are ended
|
||||
/// Spools until all user sessions are ended then switches to requested mode
|
||||
fn fire_starter(
|
||||
vendor: GfxVendors,
|
||||
devices: Vec<GraphicsDevice>,
|
||||
@@ -424,7 +433,7 @@ impl CtrlGraphics {
|
||||
killer: mpsc::Receiver<bool>,
|
||||
) -> Result<String, RogError> {
|
||||
info!("GFX: display-manager thread started");
|
||||
let mut sessions: Vec<session_manager::Session> = get_sessions().unwrap();
|
||||
let mut sessions: Vec<session_manager::Session> = get_sessions()?;
|
||||
|
||||
const SLEEP_PERIOD: Duration = Duration::from_millis(300);
|
||||
const REFRESH_COUNTDOWN: u32 = 3;
|
||||
@@ -439,7 +448,7 @@ impl CtrlGraphics {
|
||||
sleep(SLEEP_PERIOD);
|
||||
if refresh_sessions == 0 {
|
||||
refresh_sessions = REFRESH_COUNTDOWN;
|
||||
sessions = get_sessions().unwrap();
|
||||
sessions = get_sessions()?;
|
||||
}
|
||||
refresh_sessions -= 1;
|
||||
}
|
||||
@@ -472,9 +481,11 @@ impl CtrlGraphics {
|
||||
Ok(format!("Graphics mode changed to {} successfully", v))
|
||||
}
|
||||
|
||||
/// For manually calling (not on boot/startup)
|
||||
/// Initiates a mode change by starting a thread that will wait until all
|
||||
/// graphical sessions are exited before performing the tasks required
|
||||
/// to switch modes.
|
||||
///
|
||||
/// Will stop and start display manager without warning
|
||||
/// For manually calling (not on boot/startup) via dbus
|
||||
pub fn set_gfx_config(&mut self, vendor: GfxVendors) -> Result<String, RogError> {
|
||||
if let Ok(gsync) = CtrlRogBios::get_gfx_mode() {
|
||||
if gsync == 1 {
|
||||
|
||||
@@ -81,3 +81,9 @@ impl From<GraphicsError> for RogError {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SessionError> for RogError {
|
||||
fn from(err: SessionError) -> Self {
|
||||
RogError::Session(err)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,9 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = "^1.0"
|
||||
serde_json = "^1.0"
|
||||
zbus = "^1.8"
|
||||
zbus_macros = "^1.8"
|
||||
zvariant = "^2.4"
|
||||
zvariant = "^2.5"
|
||||
zvariant_derive = "^2.5"
|
||||
@@ -1,19 +1,63 @@
|
||||
mod zbus_logind;
|
||||
//! Reference https://freedesktop.org/wiki/Software/systemd/logind/
|
||||
pub mod types;
|
||||
pub mod proxy;
|
||||
|
||||
use proxy::{logind, session};
|
||||
use zbus::{Connection, Result};
|
||||
|
||||
const DEFAULT_DEST: &str = "org.freedesktop.login1";
|
||||
|
||||
pub struct Logind<'a> {
|
||||
connection: Connection,
|
||||
logind_proxy: logind::ManagerProxy<'a>,
|
||||
}
|
||||
|
||||
impl<'a> Logind<'a> {
|
||||
pub fn new() -> Result<Self> {
|
||||
let connection = Connection::new_system()?;
|
||||
let logind_proxy = logind::ManagerProxy::new(&connection)?;
|
||||
Ok(Self {
|
||||
connection,
|
||||
logind_proxy,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn logind(&self) -> &logind::ManagerProxy<'a> {
|
||||
&self.logind_proxy
|
||||
}
|
||||
|
||||
pub fn session(&self,
|
||||
path: &'a str) -> session::SessionProxy<'a> {
|
||||
let session_proxy = session::SessionProxy::new_for(&self.connection, DEFAULT_DEST, path).unwrap();
|
||||
session_proxy
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use zbus::Connection;
|
||||
|
||||
use crate::zbus_logind;
|
||||
use crate::Logind;
|
||||
use crate::types::session::SessionType;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let conn = Connection::new_system().unwrap();
|
||||
let proxy = zbus_logind::ManagerProxy::new(&conn).unwrap();
|
||||
fn basic_test() {
|
||||
let proxy = Logind::new().unwrap();
|
||||
|
||||
let sessions = proxy.list_sessions().unwrap();
|
||||
dbg!(sessions);
|
||||
let sessions = proxy.logind().list_sessions().unwrap();
|
||||
dbg!(&sessions);
|
||||
|
||||
let session_proxy = proxy.session(sessions[0].path());
|
||||
//let res = session_proxy.seat().unwrap();
|
||||
let res = session_proxy.name().unwrap();
|
||||
dbg!(res);
|
||||
let res = session_proxy.class().unwrap();
|
||||
dbg!(res);
|
||||
let res = session_proxy.type_().unwrap();
|
||||
let e:SessionType = res.as_str().into();
|
||||
dbg!(e);
|
||||
dbg!(res);
|
||||
let res = session_proxy.active().unwrap();
|
||||
dbg!(res);
|
||||
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
use crate::types::logind::{Seat, SessionInfo, User};
|
||||
|
||||
#[dbus_proxy(interface = "org.freedesktop.login1.Manager",
|
||||
default_service = "org.freedesktop.login1",
|
||||
default_path = "/org/freedesktop/login1")]
|
||||
@@ -148,15 +150,15 @@ trait Manager {
|
||||
fn list_inhibitors(&self) -> zbus::Result<Vec<(String, String, String, String, u32, u32)>>;
|
||||
|
||||
/// ListSeats method
|
||||
fn list_seats(&self) -> zbus::Result<Vec<(String, zvariant::OwnedObjectPath)>>;
|
||||
fn list_seats(&self) -> zbus::Result<Vec<Seat>>;
|
||||
|
||||
/// ListSessions method
|
||||
fn list_sessions(
|
||||
&self,
|
||||
) -> zbus::Result<Vec<(String, u32, String, String, zvariant::OwnedObjectPath)>>;
|
||||
) -> zbus::Result<Vec<SessionInfo>>;
|
||||
|
||||
/// ListUsers method
|
||||
fn list_users(&self) -> zbus::Result<Vec<(u32, String, zvariant::OwnedObjectPath)>>;
|
||||
fn list_users(&self) -> zbus::Result<Vec<User>>;
|
||||
|
||||
/// LockSession method
|
||||
fn lock_session(&self, session_id: &str) -> zbus::Result<()>;
|
||||
2
logind-zbus/src/proxy/mod.rs
Normal file
2
logind-zbus/src/proxy/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod logind;
|
||||
pub mod session;
|
||||
190
logind-zbus/src/proxy/session.rs
Normal file
190
logind-zbus/src/proxy/session.rs
Normal file
@@ -0,0 +1,190 @@
|
||||
//! # DBus interface proxy for: `org.freedesktop.login1.Session`
|
||||
//!
|
||||
//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data.
|
||||
//! Source: `Interface '/org/freedesktop/login1/session/_36' from service 'org.freedesktop.login1' on system bus`.
|
||||
//!
|
||||
//! You may prefer to adapt it, instead of using it verbatim.
|
||||
//!
|
||||
//! More information can be found in the
|
||||
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
|
||||
//! section of the zbus documentation.
|
||||
//!
|
||||
//! This DBus object implements
|
||||
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
|
||||
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
|
||||
//!
|
||||
//! * [`zbus::fdo::PeerProxy`]
|
||||
//! * [`zbus::fdo::IntrospectableProxy`]
|
||||
//! * [`zbus::fdo::PropertiesProxy`]
|
||||
//!
|
||||
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.
|
||||
|
||||
use zbus::dbus_proxy;
|
||||
|
||||
#[dbus_proxy(interface = "org.freedesktop.login1.Session",
|
||||
default_service = "org.freedesktop.login1",)]
|
||||
trait Session {
|
||||
/// Activate method
|
||||
fn activate(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Kill method
|
||||
fn kill(&self, who: &str, signal_number: i32) -> zbus::Result<()>;
|
||||
|
||||
/// Lock method
|
||||
fn lock(&self) -> zbus::Result<()>;
|
||||
|
||||
/// PauseDeviceComplete method
|
||||
fn pause_device_complete(&self, major: u32, minor: u32) -> zbus::Result<()>;
|
||||
|
||||
/// ReleaseControl method
|
||||
fn release_control(&self) -> zbus::Result<()>;
|
||||
|
||||
/// ReleaseDevice method
|
||||
fn release_device(&self, major: u32, minor: u32) -> zbus::Result<()>;
|
||||
|
||||
/// SetBrightness method
|
||||
fn set_brightness(&self, subsystem: &str, name: &str, brightness: u32) -> zbus::Result<()>;
|
||||
|
||||
/// SetIdleHint method
|
||||
fn set_idle_hint(&self, idle: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetLockedHint method
|
||||
fn set_locked_hint(&self, locked: bool) -> zbus::Result<()>;
|
||||
|
||||
/// SetType method
|
||||
fn set_type(&self, type_: &str) -> zbus::Result<()>;
|
||||
|
||||
/// TakeControl method
|
||||
fn take_control(&self, force: bool) -> zbus::Result<()>;
|
||||
|
||||
/// TakeDevice method
|
||||
fn take_device(&self, major: u32, minor: u32)
|
||||
-> zbus::Result<(std::os::unix::io::RawFd, bool)>;
|
||||
|
||||
/// Terminate method
|
||||
fn terminate(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Unlock method
|
||||
fn unlock(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Lock signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn lock(&self) -> zbus::Result<()>;
|
||||
|
||||
/// PauseDevice signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn pause_device(&self, major: u32, minor: u32, type_: &str) -> zbus::Result<()>;
|
||||
|
||||
/// ResumeDevice signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn resume_device(
|
||||
&self,
|
||||
major: u32,
|
||||
minor: u32,
|
||||
fd: std::os::unix::io::RawFd,
|
||||
) -> zbus::Result<()>;
|
||||
|
||||
/// Unlock signal
|
||||
#[dbus_proxy(signal)]
|
||||
fn unlock(&self) -> zbus::Result<()>;
|
||||
|
||||
/// Active property
|
||||
#[dbus_proxy(property)]
|
||||
fn active(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Audit property
|
||||
#[dbus_proxy(property)]
|
||||
fn audit(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// Class property
|
||||
#[dbus_proxy(property)]
|
||||
fn class(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Desktop property
|
||||
#[dbus_proxy(property)]
|
||||
fn desktop(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Display property
|
||||
#[dbus_proxy(property)]
|
||||
fn display(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Id property
|
||||
#[dbus_proxy(property)]
|
||||
fn id(&self) -> zbus::Result<String>;
|
||||
|
||||
/// IdleHint property
|
||||
#[dbus_proxy(property)]
|
||||
fn idle_hint(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// IdleSinceHint property
|
||||
#[dbus_proxy(property)]
|
||||
fn idle_since_hint(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// IdleSinceHintMonotonic property
|
||||
#[dbus_proxy(property)]
|
||||
fn idle_since_hint_monotonic(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// Leader property
|
||||
#[dbus_proxy(property)]
|
||||
fn leader(&self) -> zbus::Result<u32>;
|
||||
|
||||
/// LockedHint property
|
||||
#[dbus_proxy(property)]
|
||||
fn locked_hint(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// Name property
|
||||
#[dbus_proxy(property)]
|
||||
fn name(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Remote property
|
||||
#[dbus_proxy(property)]
|
||||
fn remote(&self) -> zbus::Result<bool>;
|
||||
|
||||
/// RemoteHost property
|
||||
#[dbus_proxy(property)]
|
||||
fn remote_host(&self) -> zbus::Result<String>;
|
||||
|
||||
/// RemoteUser property
|
||||
#[dbus_proxy(property)]
|
||||
fn remote_user(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Scope property
|
||||
#[dbus_proxy(property)]
|
||||
fn scope(&self) -> zbus::Result<String>;
|
||||
|
||||
// /// Seat property
|
||||
// #[dbus_proxy(property)]
|
||||
// fn seat(&self) -> zbus::Result<Seat>;
|
||||
|
||||
/// Service property
|
||||
#[dbus_proxy(property)]
|
||||
fn service(&self) -> zbus::Result<String>;
|
||||
|
||||
/// State property
|
||||
#[dbus_proxy(property)]
|
||||
fn state(&self) -> zbus::Result<String>;
|
||||
|
||||
/// TTY property
|
||||
#[dbus_proxy(property)]
|
||||
fn tty(&self) -> zbus::Result<String>;
|
||||
|
||||
/// Timestamp property
|
||||
#[dbus_proxy(property)]
|
||||
fn timestamp(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// TimestampMonotonic property
|
||||
#[dbus_proxy(property)]
|
||||
fn timestamp_monotonic(&self) -> zbus::Result<u64>;
|
||||
|
||||
/// Type property
|
||||
#[dbus_proxy(property)]
|
||||
fn type_(&self) -> zbus::Result<String>;
|
||||
|
||||
// /// User property
|
||||
// #[dbus_proxy(property)]
|
||||
// fn user(&self) -> zbus::Result<(u32, zvariant::OwnedObjectPath)>;
|
||||
|
||||
/// VTNr property
|
||||
#[dbus_proxy(property)]
|
||||
fn vtnr(&self) -> zbus::Result<u32>;
|
||||
}
|
||||
77
logind-zbus/src/types/logind.rs
Normal file
77
logind-zbus/src/types/logind.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use zvariant_derive::Type;
|
||||
use zvariant::OwnedObjectPath;
|
||||
|
||||
#[derive(Debug, Type, Serialize, Deserialize)]
|
||||
pub struct SessionInfo {
|
||||
/// Session ID
|
||||
sid: String,
|
||||
/// User ID
|
||||
uid: u32,
|
||||
/// Name of session user
|
||||
user: String,
|
||||
seat: String,
|
||||
path: OwnedObjectPath,
|
||||
}
|
||||
|
||||
impl SessionInfo {
|
||||
pub fn sid(&self) -> &str {
|
||||
&self.sid
|
||||
}
|
||||
|
||||
pub fn uid(&self) -> u32 {
|
||||
self.uid
|
||||
}
|
||||
|
||||
pub fn user(&self) -> &str {
|
||||
&self.user
|
||||
}
|
||||
|
||||
pub fn seat(&self) -> &str {
|
||||
&self.seat
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &OwnedObjectPath {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Type, Serialize, Deserialize)]
|
||||
pub struct Seat {
|
||||
id: String,
|
||||
/// Name of session user
|
||||
path: OwnedObjectPath,
|
||||
}
|
||||
|
||||
impl Seat {
|
||||
pub fn id(&self) -> &str {
|
||||
&self.id
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &OwnedObjectPath {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Type, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
uid: u32,
|
||||
name: String,
|
||||
/// Name of session user
|
||||
path: OwnedObjectPath,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn uid(&self) -> u32 {
|
||||
self.uid
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &str {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &OwnedObjectPath {
|
||||
&self.path
|
||||
}
|
||||
}
|
||||
2
logind-zbus/src/types/mod.rs
Normal file
2
logind-zbus/src/types/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod logind;
|
||||
pub mod session;
|
||||
24
logind-zbus/src/types/session.rs
Normal file
24
logind-zbus/src/types/session.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum SessionType {
|
||||
X11,
|
||||
Wayland,
|
||||
TTY,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl From<String> for SessionType {
|
||||
fn from(s: String) -> Self {
|
||||
<SessionType>::from(s.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for SessionType {
|
||||
fn from(s: &str) -> Self {
|
||||
match s {
|
||||
"wayland" => SessionType::Wayland,
|
||||
"x11" => SessionType::X11,
|
||||
"tty" => SessionType::TTY,
|
||||
_ => SessionType::Other(s.to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user