Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
MalpenZibo committed Dec 10, 2024
1 parent 3f92632 commit 1e6fa6c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 62 deletions.
82 changes: 43 additions & 39 deletions src/modules/keyboard_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use hyprland::{
shared::HyprData,
};
use iced::{
subscription::channel,
theme::Button,
stream::channel,
widget::{button, text},
Element, Subscription,
};
Expand Down Expand Up @@ -83,7 +82,7 @@ impl KeyboardLayout {
button(text(&self.active))
.padding([2, 7])
.on_press(Message::ChangeLayout)
.style(Button::custom(HeaderButtonStyle::Full))
.style(HeaderButtonStyle::Full.into_style())
.into(),
)
}
Expand All @@ -92,48 +91,53 @@ impl KeyboardLayout {
pub fn subscription(&self) -> Subscription<Message> {
let id = TypeId::of::<Self>();

channel(id, 10, |output| async move {
let output = Arc::new(RwLock::new(output));
loop {
let mut event_listener = AsyncEventListener::new();
Subscription::run_with_id(
id,
channel(10, |output| async move {
let output = Arc::new(RwLock::new(output));
loop {
let mut event_listener = AsyncEventListener::new();

event_listener.add_layout_changed_handler({
let output = output.clone();
move |e| {
debug!("keymap changed: {:?}", e);
event_listener.add_layout_changed_handler({
let output = output.clone();
Box::pin(async move {
if let Ok(mut output) = output.write() {
output
.try_send(Message::ActiveLayoutChanged(get_active_layout()))
.expect("error getting keymap: layout changed event");
}
})
}
});
move |e| {
debug!("keymap changed: {:?}", e);
let output = output.clone();
Box::pin(async move {
if let Ok(mut output) = output.write() {
output
.try_send(Message::ActiveLayoutChanged(get_active_layout()))
.expect("error getting keymap: layout changed event");
}
})
}
});

event_listener.add_config_reloaded_handler({
let output = output.clone();
move || {
event_listener.add_config_reloaded_handler({
let output = output.clone();
Box::pin(async move {
if let Ok(mut output) = output.write() {
output
.try_send(Message::LayoutConfigChanged(
get_multiple_layout_flag(),
))
.expect("error sending message: layout config changed event");
}
})
}
});
move || {
let output = output.clone();
Box::pin(async move {
if let Ok(mut output) = output.write() {
output
.try_send(Message::LayoutConfigChanged(
get_multiple_layout_flag(),
))
.expect(
"error sending message: layout config changed event",
);
}
})
}
});

let res = event_listener.start_listener_async().await;
let res = event_listener.start_listener_async().await;

if let Err(e) = res {
error!("restarting keymap listener due to error: {:?}", e);
if let Err(e) = res {
error!("restarting keymap listener due to error: {:?}", e);
}
}
}
})
}),
)
}
}
49 changes: 26 additions & 23 deletions src/modules/keyboard_submap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{config::KeyboardSubmapModule, style::header_pills};
use hyprland::event_listener::AsyncEventListener;
use iced::{
subscription::channel,
stream::channel,
widget::{container, text},
Element, Subscription,
};
Expand Down Expand Up @@ -53,32 +53,35 @@ impl KeyboardSubmap {
pub fn subscription(&self) -> Subscription<Message> {
let id = TypeId::of::<Self>();

channel(id, 10, |output| async move {
let output = Arc::new(RwLock::new(output));
loop {
let mut event_listener = AsyncEventListener::new();
Subscription::run_with_id(
id,
channel(10, |output| async move {
let output = Arc::new(RwLock::new(output));
loop {
let mut event_listener = AsyncEventListener::new();

event_listener.add_sub_map_changed_handler({
let output = output.clone();
move |new_submap| {
debug!("submap changed: {:?}", new_submap);
event_listener.add_sub_map_changed_handler({
let output = output.clone();
Box::pin(async move {
if let Ok(mut output) = output.write() {
output
.try_send(Message::SubmapChanged(new_submap))
.expect("error getting submap: submap changed event");
}
})
}
});
move |new_submap| {
debug!("submap changed: {:?}", new_submap);
let output = output.clone();
Box::pin(async move {
if let Ok(mut output) = output.write() {
output
.try_send(Message::SubmapChanged(new_submap))
.expect("error getting submap: submap changed event");
}
})
}
});

let res = event_listener.start_listener_async().await;
let res = event_listener.start_listener_async().await;

if let Err(e) = res {
error!("restarting submap listener due to error: {:?}", e);
if let Err(e) = res {
error!("restarting submap listener due to error: {:?}", e);
}
}
}
})
}),
)
}
}

0 comments on commit 1e6fa6c

Please sign in to comment.