diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-25 03:24:45 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-25 03:24:45 -0700 |
| commit | 5ec7ae026ce9d8c48ef5f0590a300fa308efa487 (patch) | |
| tree | b0f5b2e19d724a548ee36ad636d114666d201318 /src/module/i3_mode.rs | |
| parent | 6ab1eb29d593af69aef18ddcfadd171c07aac2ed (diff) | |
i3 mode module does the subscription now
Force-Push: yes Change-Id: I2996d58c4eb605caa904f23f876853fc3eb9761d
Diffstat (limited to 'src/module/i3_mode.rs')
| -rw-r--r-- | src/module/i3_mode.rs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/module/i3_mode.rs b/src/module/i3_mode.rs index 6151d90..d02f12d 100644 --- a/src/module/i3_mode.rs +++ b/src/module/i3_mode.rs @@ -1,19 +1,39 @@ -use crate::error::Result; +use crate::error::{ Error, Result }; use crate::facility::{ FacilityMap, FacilityType }; +use crate::facility::i3::{ EventType, I3 }; use crate::module::{ CreatableModule, Module }; use std::time::Duration; +use async_channel::{ unbounded, Receiver }; +use async_executor::StaticExecutor; +use async_task::Task; + pub struct I3ModeModule { + update_task: Task<()>, } impl CreatableModule for I3ModeModule { const REQUIRED_FACILITIES: FacilityType = FacilityType::I3; - fn new(_facilities: &mut FacilityMap) -> Result<I3ModeModule> { - Ok(I3ModeModule { }) + async fn new(facilities: &mut FacilityMap, + executor: &'static StaticExecutor) + -> Result<I3ModeModule> + { + let i3: &mut I3 = facilities.get().ok_or(Error::custom( + "I3 mode module can't access i3 facility."))?; + + let (sender, receiver) = unbounded(); + + if !i3.subscribe(EventType::MODE, sender).await? { + return Err(Error::custom("Unable to subscribe to i3 mode changes.")); + } + + let update_task = executor.spawn(update_loop(receiver)); + + Ok(I3ModeModule { update_task }) } } @@ -31,3 +51,17 @@ impl Module for I3ModeModule { } } + +async fn update_loop(receiver: Receiver<(EventType, String)>) { + loop { + match receiver.recv().await { + Ok((_, body)) => { + println!("it worked??? {}", body); + } + Err(error) => { + Into::<Error>::into(error).log(); + } + } + } +} + |