Struct I3EventListener

Source
pub struct I3EventListener { /* private fields */ }
Expand description

Abstraction over an ipc socket to i3. Handles events.

Implementations§

Source§

impl I3EventListener

Source

pub fn connect() -> Result<I3EventListener, EstablishError>

Establishes the IPC connection.

Examples found in repository?
examples/event_printer.rs (line 10)
9fn main() {
10    let mut listener = I3EventListener::connect().expect("failed to connect");
11    let subs = [
12        Subscription::Workspace,
13        Subscription::Output,
14        Subscription::Mode,
15        Subscription::Window,
16        Subscription::BarConfig,
17        Subscription::Binding,
18    ];
19    listener.subscribe(&subs).expect("failed to subscribe");
20    for event in listener.listen() {
21        println!("{:?}\n", event.expect("failed to get event"))
22    }
23}
More examples
Hide additional examples
examples/hovered_window.rs (line 10)
9fn main() {
10    let mut listener = I3EventListener::connect().expect("failed to connect");
11    listener
12        .subscribe(&[Subscription::Window])
13        .expect("failed to subscribe");
14    for event in listener.listen() {
15        match event {
16            Ok(Event::WindowEvent(w)) => {
17                println!("{}", w.container.name.unwrap_or("unnamed".to_owned()))
18            }
19            Err(e) => println!("Error: {}", e),
20            _ => unreachable!(),
21        }
22    }
23}
Source

pub fn subscribe( &mut self, events: &[Subscription], ) -> Result<Subscribe, MessageError>

Subscribes your connection to certain events.

Examples found in repository?
examples/event_printer.rs (line 19)
9fn main() {
10    let mut listener = I3EventListener::connect().expect("failed to connect");
11    let subs = [
12        Subscription::Workspace,
13        Subscription::Output,
14        Subscription::Mode,
15        Subscription::Window,
16        Subscription::BarConfig,
17        Subscription::Binding,
18    ];
19    listener.subscribe(&subs).expect("failed to subscribe");
20    for event in listener.listen() {
21        println!("{:?}\n", event.expect("failed to get event"))
22    }
23}
More examples
Hide additional examples
examples/hovered_window.rs (line 12)
9fn main() {
10    let mut listener = I3EventListener::connect().expect("failed to connect");
11    listener
12        .subscribe(&[Subscription::Window])
13        .expect("failed to subscribe");
14    for event in listener.listen() {
15        match event {
16            Ok(Event::WindowEvent(w)) => {
17                println!("{}", w.container.name.unwrap_or("unnamed".to_owned()))
18            }
19            Err(e) => println!("Error: {}", e),
20            _ => unreachable!(),
21        }
22    }
23}
Source

pub fn listen(&mut self) -> EventIterator<'_>

Iterate over subscribed events forever.

Examples found in repository?
examples/event_printer.rs (line 20)
9fn main() {
10    let mut listener = I3EventListener::connect().expect("failed to connect");
11    let subs = [
12        Subscription::Workspace,
13        Subscription::Output,
14        Subscription::Mode,
15        Subscription::Window,
16        Subscription::BarConfig,
17        Subscription::Binding,
18    ];
19    listener.subscribe(&subs).expect("failed to subscribe");
20    for event in listener.listen() {
21        println!("{:?}\n", event.expect("failed to get event"))
22    }
23}
More examples
Hide additional examples
examples/hovered_window.rs (line 14)
9fn main() {
10    let mut listener = I3EventListener::connect().expect("failed to connect");
11    listener
12        .subscribe(&[Subscription::Window])
13        .expect("failed to subscribe");
14    for event in listener.listen() {
15        match event {
16            Ok(Event::WindowEvent(w)) => {
17                println!("{}", w.container.name.unwrap_or("unnamed".to_owned()))
18            }
19            Err(e) => println!("Error: {}", e),
20            _ => unreachable!(),
21        }
22    }
23}

Trait Implementations§

Source§

impl Debug for I3EventListener

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.