Fix compositor output routing and pointer hints; format imports
This commit is contained in:
1 parent
88e4f3c135
commit
46509f880a
108 files changed
+3682
-8371
No files matched your search
@@ -1,6 +1,8 @@
|
||||
//! BlueZ status from its object graph; never starts discovery or pairing.
|
||||
use zbus::blocking::Connection;
|
||||
use zbus::fdo::ManagedObjects;
|
||||
|
||||
use super::Bluetooth;
|
||||
use zbus::{blocking::Connection, fdo::ManagedObjects};
|
||||
|
||||
pub(super) fn read(connection: &Connection) -> zbus::Result<Option<Bluetooth>> {
|
||||
let objects: ManagedObjects = connection
|
||||
@@ -35,10 +37,7 @@ pub(super) fn read(connection: &Connection) -> zbus::Result<Option<Bluetooth>> {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some((path, _)) = adapters.iter().find(|(_, properties)| {
|
||||
properties
|
||||
.get("Address")
|
||||
.and_then(|value| <&str>::try_from(value).ok())
|
||||
== Some(address)
|
||||
properties.get("Address").and_then(|value| <&str>::try_from(value).ok()) == Some(address)
|
||||
}) else {
|
||||
return Ok(None);
|
||||
};
|
||||
@@ -78,8 +77,9 @@ fn snapshot(objects: &ManagedObjects, selected: Option<&str>) -> Option<Bluetoot
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use zbus::zvariant::{OwnedObjectPath, OwnedValue, Str};
|
||||
|
||||
use super::*;
|
||||
fn graph() -> ManagedObjects {
|
||||
let mut graph = ManagedObjects::new();
|
||||
for (path, powered) in [("/org/bluez/hci0", true), ("/org/bluez/hci1", false)] {
|
||||
@@ -93,24 +93,9 @@ mod tests {
|
||||
);
|
||||
}
|
||||
for (path, adapter, connected, alias) in [
|
||||
(
|
||||
"/org/bluez/hci0/dev_a",
|
||||
"/org/bluez/hci0",
|
||||
true,
|
||||
"Headphones",
|
||||
),
|
||||
(
|
||||
"/org/bluez/hci0/dev_b",
|
||||
"/org/bluez/hci0",
|
||||
false,
|
||||
"Keyboard",
|
||||
),
|
||||
(
|
||||
"/org/bluez/hci1/dev_a",
|
||||
"/org/bluez/hci1",
|
||||
true,
|
||||
"Other adapter",
|
||||
),
|
||||
("/org/bluez/hci0/dev_a", "/org/bluez/hci0", true, "Headphones"),
|
||||
("/org/bluez/hci0/dev_b", "/org/bluez/hci0", false, "Keyboard"),
|
||||
("/org/bluez/hci1/dev_a", "/org/bluez/hci1", true, "Other adapter"),
|
||||
] {
|
||||
graph.insert(
|
||||
OwnedObjectPath::try_from(path).unwrap(),
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
//! Keep native snapshots until the owning service signals a change.
|
||||
use super::StatusBus;
|
||||
use cosmic::iced::futures::{FutureExt, StreamExt, channel::oneshot};
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use cosmic::iced::futures::channel::oneshot;
|
||||
use cosmic::iced::futures::{FutureExt, StreamExt};
|
||||
use zbus::blocking::{Connection, MessageIterator};
|
||||
|
||||
use super::StatusBus;
|
||||
|
||||
struct Signals {
|
||||
revision: Arc<AtomicU64>,
|
||||
alive: Arc<AtomicBool>,
|
||||
@@ -44,9 +45,7 @@ impl Signals {
|
||||
let (stop, stopped) = oneshot::channel::<()>();
|
||||
std::thread::spawn(move || {
|
||||
// Enter a runtime for zbus stream cleanup, including cancellation.
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build();
|
||||
let runtime = tokio::runtime::Builder::new_current_thread().enable_all().build();
|
||||
if let Ok(runtime) = runtime {
|
||||
// Dropping the blocking wrappers enters zbus' runtime, so do
|
||||
// this before entering our async runtime.
|
||||
@@ -102,32 +101,19 @@ impl<T: Clone> Cache<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn read(
|
||||
&mut self,
|
||||
action: u64,
|
||||
read: fn(&Connection) -> zbus::Result<Option<T>>,
|
||||
) -> Option<T> {
|
||||
if self
|
||||
.signals
|
||||
.as_ref()
|
||||
.is_some_and(|s| !s.alive.load(Ordering::Acquire))
|
||||
{
|
||||
pub(super) fn read(&mut self, action: u64, read: fn(&Connection) -> zbus::Result<Option<T>>) -> Option<T> {
|
||||
if self.signals.as_ref().is_some_and(|s| !s.alive.load(Ordering::Acquire)) {
|
||||
self.signals = None;
|
||||
self.bus.connection = None;
|
||||
self.value = None;
|
||||
}
|
||||
if self.signals.is_none() {
|
||||
self.signals = self
|
||||
.bus
|
||||
.query(|connection| Signals::new(connection, self.service));
|
||||
self.signals = self.bus.query(|connection| Signals::new(connection, self.service));
|
||||
self.revision = 0;
|
||||
}
|
||||
// If subscription setup fails, read fresh rather than trusting a cache
|
||||
// with no invalidation. Retry setup on the next regular status poll.
|
||||
let revision = self
|
||||
.signals
|
||||
.as_ref()
|
||||
.map(|s| s.revision.load(Ordering::Acquire));
|
||||
let revision = self.signals.as_ref().map(|s| s.revision.load(Ordering::Acquire));
|
||||
if revision.is_none()
|
||||
|| revision != Some(self.revision)
|
||||
|| action != self.action
|
||||
@@ -149,8 +135,9 @@ impl<T: Clone> Cache<T> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use super::*;
|
||||
struct Counter(Arc<AtomicU64>);
|
||||
#[zbus::interface(name = "org.ferese.StatusCounter")]
|
||||
impl Counter {
|
||||
@@ -193,13 +180,7 @@ mod tests {
|
||||
assert_eq!(count.load(Ordering::Relaxed), 1);
|
||||
assert_eq!(cache.read(1, read_counter), Some(2));
|
||||
server
|
||||
.emit_signal(
|
||||
None::<&str>,
|
||||
"/test",
|
||||
"org.ferese.StatusCounter",
|
||||
"Changed",
|
||||
&(),
|
||||
)
|
||||
.emit_signal(None::<&str>, "/test", "org.ferese.StatusCounter", "Changed", &())
|
||||
.unwrap();
|
||||
let deadline = Instant::now() + Duration::from_secs(2);
|
||||
while cache.read(1, read_counter) != Some(3) {
|
||||
@@ -247,13 +228,7 @@ mod tests {
|
||||
};
|
||||
let before = signals.revision.load(Ordering::Acquire);
|
||||
server
|
||||
.emit_signal(
|
||||
None::<&str>,
|
||||
"/test",
|
||||
"org.ferese.StatusTest",
|
||||
"Changed",
|
||||
&(),
|
||||
)
|
||||
.emit_signal(None::<&str>, "/test", "org.ferese.StatusTest", "Changed", &())
|
||||
.unwrap();
|
||||
wait(before);
|
||||
let before = signals.revision.load(Ordering::Acquire);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//! Read NetworkManager directly; no scans or network changes are requested.
|
||||
use zbus::blocking::Connection;
|
||||
use zbus::zvariant::OwnedObjectPath;
|
||||
|
||||
use super::Network;
|
||||
use zbus::{blocking::Connection, zvariant::OwnedObjectPath};
|
||||
|
||||
const SERVICE: &str = "org.freedesktop.NetworkManager";
|
||||
const ROOT: &str = "/org/freedesktop/NetworkManager";
|
||||
@@ -86,8 +88,9 @@ pub(super) fn read(connection: &Connection) -> zbus::Result<Option<Network>> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use super::*;
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
wifi: bool,
|
||||
@@ -120,12 +123,7 @@ mod tests {
|
||||
impl Wireless {
|
||||
#[zbus(property)]
|
||||
fn active_access_point(&self) -> OwnedObjectPath {
|
||||
OwnedObjectPath::try_from(if self.0.lock().unwrap().active {
|
||||
"/ap"
|
||||
} else {
|
||||
"/"
|
||||
})
|
||||
.unwrap()
|
||||
OwnedObjectPath::try_from(if self.0.lock().unwrap().active { "/ap" } else { "/" }).unwrap()
|
||||
}
|
||||
}
|
||||
struct Ap(Arc<Mutex<State>>);
|
||||
|
||||
Reference in new issue
Block a user