pub struct I3Stream(_);
Expand description
I3Stream
will hold the underlying UnixStream that communicates with i3
Implementations§
source§impl I3Stream
impl I3Stream
sourcepub fn conn_sub<E>(events: E) -> Result<Self>where
E: AsRef<[Subscribe]>,
pub fn conn_sub<E>(events: E) -> Result<Self>where
E: AsRef<[Subscribe]>,
Connect & subscribe in one method
Examples found in repository?
examples/sync_listen.rs (line 9)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() -> io::Result<()> {
let mut i3 = I3Stream::conn_sub(&[Subscribe::Window, Subscribe::Workspace])?;
for e in i3.listen() {
match e? {
Event::Workspace(ev) => println!("workspace change event {:?}", ev),
Event::Window(ev) => println!("window event {:?}", ev),
Event::Output(ev) => println!("output event {:?}", ev),
Event::Mode(ev) => println!("mode event {:?}", ev),
Event::BarConfig(ev) => println!("bar config update {:?}", ev),
Event::Binding(ev) => println!("binding event {:?}", ev),
Event::Shutdown(ev) => println!("shutdown event {:?}", ev),
Event::Tick(ev) => println!("tick event {:?}", ev),
}
}
Ok(())
}
sourcepub fn subscribe<E>(&mut self, events: E) -> Result<Success>where
E: AsRef<[Subscribe]>,
pub fn subscribe<E>(&mut self, events: E) -> Result<Success>where
E: AsRef<[Subscribe]>,
sends a subscribe message to i3 with a json encoded array of types of events to listen to
sourcepub fn listen(&mut self) -> I3Iter<'_> ⓘ
pub fn listen(&mut self) -> I3Iter<'_> ⓘ
Returns a type that implements Iterator
, allowing us to listen to
events
Examples found in repository?
examples/sync_listen.rs (line 10)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() -> io::Result<()> {
let mut i3 = I3Stream::conn_sub(&[Subscribe::Window, Subscribe::Workspace])?;
for e in i3.listen() {
match e? {
Event::Workspace(ev) => println!("workspace change event {:?}", ev),
Event::Window(ev) => println!("window event {:?}", ev),
Event::Output(ev) => println!("output event {:?}", ev),
Event::Mode(ev) => println!("mode event {:?}", ev),
Event::BarConfig(ev) => println!("bar config update {:?}", ev),
Event::Binding(ev) => println!("binding event {:?}", ev),
Event::Shutdown(ev) => println!("shutdown event {:?}", ev),
Event::Tick(ev) => println!("tick event {:?}", ev),
}
}
Ok(())
}
sourcepub fn send_msg<P>(&mut self, msg: Msg, payload: P) -> Result<usize>where
P: AsRef<str>,
pub fn send_msg<P>(&mut self, msg: Msg, payload: P) -> Result<usize>where
P: AsRef<str>,
Send a message and payload, used for get_*
commands and run_command
sourcepub fn receive_msg<D: DeserializeOwned>(&mut self) -> Result<MsgResponse<D>>
pub fn receive_msg<D: DeserializeOwned>(&mut self) -> Result<MsgResponse<D>>
Receive some message from the socket. Holds a Msg
type and payload
sourcepub fn receive_event(&mut self) -> Result<Event>
pub fn receive_event(&mut self) -> Result<Event>
Like receive_msg
but for event::Event
sourcepub fn send_receive<P, D>(
&mut self,
msg: Msg,
payload: P
) -> Result<MsgResponse<D>>where
P: AsRef<str>,
D: DeserializeOwned,
pub fn send_receive<P, D>(
&mut self,
msg: Msg,
payload: P
) -> Result<MsgResponse<D>>where
P: AsRef<str>,
D: DeserializeOwned,
Send a Msg
and payload and receive a response. Convenience function
over send_msg
and receive_msg
sourcepub fn run_command<S: AsRef<str>>(&mut self, payload: S) -> Result<Vec<Success>>
pub fn run_command<S: AsRef<str>>(&mut self, payload: S) -> Result<Vec<Success>>
Run an arbitrary command on i3.
sourcepub fn get_workspaces(&mut self) -> Result<Workspaces>
pub fn get_workspaces(&mut self) -> Result<Workspaces>
Get active workspaces
sourcepub fn get_outputs(&mut self) -> Result<Outputs>
pub fn get_outputs(&mut self) -> Result<Outputs>
Get active workspaces
sourcepub fn get_bar_ids(&mut self) -> Result<BarIds>
pub fn get_bar_ids(&mut self) -> Result<BarIds>
Get your active bar ids
sourcepub fn get_bar_config<S: AsRef<str>>(&mut self, bar_id: S) -> Result<BarConfig>
pub fn get_bar_config<S: AsRef<str>>(&mut self, bar_id: S) -> Result<BarConfig>
Get bar config by id (get_bar_ids
)
sourcepub fn get_version(&mut self) -> Result<Version>
pub fn get_version(&mut self) -> Result<Version>
Get i3 version and config location
sourcepub fn get_binding_modes(&mut self) -> Result<BindingModes>
pub fn get_binding_modes(&mut self) -> Result<BindingModes>
Get i3 binding modes
sourcepub fn get_config(&mut self) -> Result<Config>
pub fn get_config(&mut self) -> Result<Config>
Get i3 config
sourcepub fn get_binding_state(&mut self) -> Result<BindingState>
pub fn get_binding_state(&mut self) -> Result<BindingState>
Get i3 binding state
Trait Implementations§
source§impl I3Protocol for I3Stream
impl I3Protocol for I3Stream
const MAGIC: &'static str = MAGIC
fn _encode_msg<P>(&self, msg: Msg, payload: Option<P>) -> Vec<u8, Global>where
P: AsRef<str>,
fn encode_msg(&self, msg: Msg) -> Vec<u8, Global>
fn encode_msg_body<P>(&self, msg: Msg, payload: P) -> Vec<u8, Global>where
P: AsRef<str>,
fn encode_msg_json<P>(
&self,
msg: Msg,
payload: P
) -> Result<Vec<u8, Global>, Error>where
P: Serialize,
fn decode_event(evt_type: u32, payload: Vec<u8, Global>) -> Result<Event, Error>
source§impl Read for I3Stream
impl Read for I3Stream
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Pull some bytes from this source into the specified buffer. Read more
source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Read the exact number of bytes required to fill
cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adaptor for this instance of
Read
. Read moresource§impl Write for I3Stream
impl Write for I3Stream
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered
contents reach their destination. Read more
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more