mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-23 17:18:40 +02:00
fix(bar): pass reconnect event to bar
This commit changes the `rx_gui` from receiving just a notification from komorebi to now receive a new type `KomorebiEvent` which can be either a `KomorebiEvent::Notification(komorebi_client::Notification)` or a `KomorebiEvent::Reconnect`. The `Reconnect` is sent after losing connection with komorebi and then reconnecting again. Now on the bar `update` we check for this `rx_gui` if we get a notification we pass that to the `KomorebiNotificationState::handle_notification` function just like before (except now it takes a notification directly instead of taking the `rx_gui` and checking for some message on the channel). If instead we get a `Reconnect` we send a `MonitorWorkAreaOffset` socket message to komorebi to update the work area offset.
This commit is contained in:
@@ -115,6 +115,11 @@ fn process_hwnd() -> Option<isize> {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum KomorebiEvent {
|
||||
Notification(komorebi_client::Notification),
|
||||
Reconnect,
|
||||
}
|
||||
|
||||
fn main() -> color_eyre::Result<()> {
|
||||
unsafe { SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) }?;
|
||||
|
||||
@@ -333,8 +338,6 @@ fn main() -> color_eyre::Result<()> {
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
let config_cl = config_arc.clone();
|
||||
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
@@ -377,25 +380,12 @@ fn main() -> color_eyre::Result<()> {
|
||||
|
||||
tracing::info!("reconnected to komorebi");
|
||||
|
||||
let (monitor_index, work_area_offset) = match &config_cl.monitor {
|
||||
MonitorConfigOrIndex::MonitorConfig(monitor_config) => {
|
||||
(monitor_config.index, monitor_config.work_area_offset)
|
||||
}
|
||||
MonitorConfigOrIndex::Index(idx) => (*idx, None),
|
||||
};
|
||||
|
||||
if let Some(rect) = &work_area_offset {
|
||||
while komorebi_client::send_message(
|
||||
&SocketMessage::MonitorWorkAreaOffset(
|
||||
monitor_index,
|
||||
*rect,
|
||||
),
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Reconnect) {
|
||||
tracing::error!("could not send komorebi reconnect event to gui thread: {error}")
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
continue;
|
||||
}
|
||||
|
||||
match String::from_utf8(buffer) {
|
||||
@@ -406,7 +396,7 @@ fn main() -> color_eyre::Result<()> {
|
||||
Ok(notification) => {
|
||||
tracing::debug!("received notification from komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(notification) {
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Notification(notification)) {
|
||||
tracing::error!("could not send komorebi notification update to gui thread: {error}")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user