Fix compositor output routing and pointer hints; format imports

This commit is contained in:
Samuel Onoja committed 2026-09-30 06:39:58 +01:00
1 parent 88e4f3c135
commit 46509f880a
108 files changed
+3682 -8371

No files matched your search

+22 -41
View File
@@ -1,9 +1,8 @@
use std::os::unix::net::UnixStream;
use std::path::PathBuf;
use std::time::{Duration, Instant};
use serde_json::{Value, json};
use std::{
os::unix::net::UnixStream,
path::PathBuf,
time::{Duration, Instant},
};
pub(super) fn call(command: &str) -> Result<Value, String> {
request(command, json!({}))
@@ -33,10 +32,7 @@ impl SessionConnection {
}
fn request(&self, command: &str, args: Value) -> Result<Value, String> {
let mut stream = self
.stream
.lock()
.map_err(|_| "Compositor connection failed")?;
let mut stream = self.stream.lock().map_err(|_| "Compositor connection failed")?;
let request = ferese_ipc::Request {
version: ferese_ipc::VERSION,
id: 1,
@@ -45,8 +41,7 @@ impl SessionConnection {
args,
};
ferese_ipc::write_frame(&mut *stream, &request).map_err(|error| error.to_string())?;
let response: ferese_ipc::Response =
ferese_ipc::read_frame(&mut *stream).map_err(|error| error.to_string())?;
let response: ferese_ipc::Response = ferese_ipc::read_frame(&mut *stream).map_err(|error| error.to_string())?;
if let Some(error) = response.error {
return Err(error.message);
}
@@ -89,24 +84,21 @@ impl Approval {
}
pub fn prepare(&self) -> Result<(), String> {
if matches!(self.mode, Mode::Shutdown | Mode::Suspend)
&& login_inhibitors(self.mode)? != self.external
{
return Err(
"Applications changed their inhibitors; review the confirmation again".into(),
);
if matches!(self.mode, Mode::Shutdown | Mode::Suspend) && login_inhibitors(self.mode)? != self.external {
return Err("Applications changed their inhibitors; review the confirmation again".into());
}
if self.mode == Mode::Shutdown {
self.connection.as_ref().ok_or("Missing session-ending lease")?.request(
"validate-session-end",
json!({"token": self.token, "inhibitor-revision": self.revision, "force": self.force()}),
)?;
self.connection
.as_ref()
.ok_or("Missing session-ending lease")?
.request(
"validate-session-end",
json!({"token": self.token, "inhibitor-revision": self.revision, "force": self.force()}),
)?;
} else if self.mode == Mode::Suspend {
let state = call("get-session-state")?;
if state["inhibitor-revision"].as_u64() != Some(u64::from(self.revision)) {
return Err(
"Applications changed their inhibitors; review the confirmation again".into(),
);
return Err("Applications changed their inhibitors; review the confirmation again".into());
}
}
Ok(())
@@ -129,19 +121,12 @@ fn login_inhibitors(mode: Mode) -> Result<Vec<String>, String> {
"org.freedesktop.login1.Manager",
)
.map_err(|error| error.to_string())?;
let inhibitors: Vec<(String, String, String, String, u32, u32)> = proxy
.call("ListInhibitors", &())
.map_err(|error| error.to_string())?;
let what = if mode == Mode::Suspend {
"sleep"
} else {
"shutdown"
};
let inhibitors: Vec<(String, String, String, String, u32, u32)> =
proxy.call("ListInhibitors", &()).map_err(|error| error.to_string())?;
let what = if mode == Mode::Suspend { "sleep" } else { "shutdown" };
let mut reasons = inhibitors
.into_iter()
.filter(|(flags, _, _, inhibition, _, _)| {
inhibition == "block" && flags.split(':').any(|flag| flag == what)
})
.filter(|(flags, _, _, inhibition, _, _)| inhibition == "block" && flags.split(':').any(|flag| flag == what))
.map(|(_, app, reason, _, _, _)| format!("{app}: {reason}"))
.collect::<Vec<_>>();
reasons.sort();
@@ -181,9 +166,7 @@ pub(super) fn inhibitors(mode: Mode) -> Result<Approval, String> {
}
}
let flags = if mode == Mode::Suspend { 4 } else { 1 };
let entries = state["inhibitors"]
.as_array()
.ok_or("Invalid inhibitor list")?;
let entries = state["inhibitors"].as_array().ok_or("Invalid inhibitor list")?;
let mut reasons = entries
.iter()
.filter(|entry| entry["flags"].as_u64().unwrap_or(0) & flags != 0)
@@ -192,9 +175,7 @@ pub(super) fn inhibitors(mode: Mode) -> Result<Approval, String> {
.as_str()
.filter(|app| !app.is_empty())
.unwrap_or("Application");
let reason = entry["reason"]
.as_str()
.unwrap_or("Requested session inhibition");
let reason = entry["reason"].as_str().unwrap_or("Requested session inhibition");
format!("{app}: {reason}")
})
.collect::<Vec<_>>();