Skip to content

Commit

Permalink
refactor(bar): use monitor idx when switching ws
Browse files Browse the repository at this point in the history
This commit follows up on a point made by @notTamion in #1128 - since we
have the monitor index, we can use it in the bar's workspace widget to
more accurately target workspaces via
SocketMessage::FocusMonitorWorkspaceNumber.
  • Loading branch information
LGUG2Z committed Nov 20, 2024
1 parent 779c12b commit 041ef57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions komorebi-bar/src/komorebi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::render::RenderConfig;
use crate::ui::CustomUi;
use crate::widget::BarWidget;
use crate::MAX_LABEL_WIDTH;
use crate::MONITOR_INDEX;
use crossbeam_channel::Receiver;
use crossbeam_channel::TryRecvError;
use eframe::egui::text::LayoutJob;
Expand Down Expand Up @@ -103,6 +104,7 @@ impl From<&KomorebiConfig> for Komorebi {
work_area_offset: None,
focused_container_information: (vec![], vec![], 0),
stack_accent: None,
monitor_index: MONITOR_INDEX.load(Ordering::SeqCst),
})),
workspaces: value.workspaces,
layout: value.layout,
Expand Down Expand Up @@ -154,9 +156,12 @@ impl BarWidget for Komorebi {
}

if proceed
&& komorebi_client::send_message(&SocketMessage::FocusWorkspaceNumber(
i,
))
&& komorebi_client::send_message(
&SocketMessage::FocusMonitorWorkspaceNumber(
komorebi_notification_state.monitor_index,
i,
),
)
.is_err()
{
tracing::error!(
Expand Down Expand Up @@ -435,6 +440,7 @@ pub struct KomorebiNotificationState {
pub mouse_follows_focus: bool,
pub work_area_offset: Option<Rect>,
pub stack_accent: Option<Color32>,
pub monitor_index: usize,
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -497,6 +503,8 @@ impl KomorebiNotificationState {
},
}

self.monitor_index = monitor_index;

self.mouse_follows_focus = notification.state.mouse_follows_focus;

let monitor = &notification.state.monitors.elements()[monitor_index];
Expand Down
4 changes: 4 additions & 0 deletions komorebi-bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::io::BufReader;
use std::io::Read;
use std::path::PathBuf;
use std::sync::atomic::AtomicI32;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -47,6 +48,7 @@ pub static MAX_LABEL_WIDTH: AtomicI32 = AtomicI32::new(400);
pub static MONITOR_LEFT: AtomicI32 = AtomicI32::new(0);
pub static MONITOR_TOP: AtomicI32 = AtomicI32::new(0);
pub static MONITOR_RIGHT: AtomicI32 = AtomicI32::new(0);
pub static MONITOR_INDEX: AtomicUsize = AtomicUsize::new(0);
pub static BAR_HEIGHT: f32 = 50.0;

#[derive(Parser)]
Expand Down Expand Up @@ -233,6 +235,8 @@ fn main() -> color_eyre::Result<()> {
Ordering::SeqCst,
);

MONITOR_INDEX.store(config.monitor.index, Ordering::SeqCst);

match config.position {
None => {
config.position = Some(PositionConfig {
Expand Down

0 comments on commit 041ef57

Please sign in to comment.