diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-24 01:20:34 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-24 01:20:34 -0700 |
| commit | 7465b56cc11bb4b17ba8d994142da0b74cbb8c7e (patch) | |
| tree | fc0efe6ea6d63dce0491c72b08cb0e6c420df5be /src/facility/i3.rs | |
| parent | d0a03210efd08d2fbf61fa37e000fc1f4622b46a (diff) | |
actually open the i3 socket now
yay Force-Push: yes Change-Id: I93f991f29d71f91b03a9a43179c59cf4d6b64d70
Diffstat (limited to 'src/facility/i3.rs')
| -rw-r--r-- | src/facility/i3.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/facility/i3.rs b/src/facility/i3.rs index 4b91b02..c2f9878 100644 --- a/src/facility/i3.rs +++ b/src/facility/i3.rs @@ -6,13 +6,14 @@ use crate::xdg::xdg_runtime_directory; use std::any::Any; use std::path::{ Path, PathBuf }; -use async_fs::{ metadata, read_dir, File, OpenOptions }; +use async_fs::{ metadata, read_dir }; use async_fs::unix::FileTypeExt; +use async_net::unix::UnixStream; use futures_lite::StreamExt; pub struct I3 { - socket: File, + socket: UnixStream, } @@ -37,7 +38,7 @@ impl CreatableFacility for I3 { } impl I3 { - async fn find_socket() -> Result<File> { + async fn find_socket() -> Result<UnixStream> { /* We save most errors for the end, because they aren't really errors if * a subsequent attempt succeeds. */ @@ -97,7 +98,7 @@ impl I3 { * for subdirectories with names having a specific pattern. Do that. */ async fn try_tmp_directory(path: &Path, username: &str) - -> Result<Option<File>> + -> Result<Option<UnixStream>> { let mut directory = read_dir(path).await?; @@ -135,7 +136,7 @@ impl I3 { * The directory iteration logic is a lot like that for try_tmp_directory(). * In principle, it could make sense to write a helper. */ - async fn try_socket_directory(path: &Path) -> Result<Option<File>> { + async fn try_socket_directory(path: &Path) -> Result<Option<UnixStream>> { let mut directory = read_dir(path).await?; while let Some(entry) = directory.try_next().await? { @@ -165,15 +166,20 @@ impl I3 { } /* If we have a candidate full path to an i3 socket, see if it works. */ - async fn try_socket_path(path: &Path) -> Result<Option<File>> { + async fn try_socket_path(path: &Path) -> Result<Option<UnixStream>> { /* Do follow symlinks, for the socket check. */ if !metadata(path).await?.file_type().is_socket() { return Ok(None); } - /* Unix-domain sockets don't use open(), despite appearing in the filesystem. TODO */ - let socket = OpenOptions::new().read(true).write(true).open(path).await?; - println!("got i3 socket {:?}", path); + /* Unix-domain sockets don't use open(), despite appearing in the + * filesystem. If you think about it, that makes sense: Each process that + * opens it gets its own send/receive pair. It's not like a pipe. + */ + let socket = UnixStream::connect(path).await?; + + println!("Found i3 socket {}", path.display()); + Ok(Some(socket)) } } |