fix(bar): retain exact workspace indices

This commit ensures that the exact workspace indices are tracked in the
komorebi widget state.

This fixes a bug where an incorrect workspace index could be sent with
SocketMessage::FocusWorkspaceNumber if a user had hide_empty_workspaces
set to true.

fix #1102
This commit is contained in:
LGUG2Z
2024-11-04 17:01:19 -08:00
parent 0f022d47df
commit 36e3eaad36
+15 -13
View File
@@ -128,13 +128,15 @@ impl BarWidget for Komorebi {
if self.workspaces.enable { if self.workspaces.enable {
let mut update = None; let mut update = None;
for (i, ws) in komorebi_notification_state.workspaces.iter().enumerate() { for (i, (ws, should_show)) in komorebi_notification_state.workspaces.iter().enumerate()
if ui {
.add(SelectableLabel::new( if *should_show
komorebi_notification_state.selected_workspace.eq(ws), && ui
ws.to_string(), .add(SelectableLabel::new(
)) komorebi_notification_state.selected_workspace.eq(ws),
.clicked() ws.to_string(),
))
.clicked()
{ {
update = Some(ws.to_string()); update = Some(ws.to_string());
let mut proceed = true; let mut proceed = true;
@@ -400,7 +402,7 @@ fn img_to_texture(ctx: &Context, rgba_image: &RgbaImage) -> TextureHandle {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct KomorebiNotificationState { pub struct KomorebiNotificationState {
pub workspaces: Vec<String>, pub workspaces: Vec<(String, bool)>,
pub selected_workspace: String, pub selected_workspace: String,
pub focused_container_information: (Vec<String>, Vec<Option<RgbaImage>>, usize), pub focused_container_information: (Vec<String>, Vec<Option<RgbaImage>>, usize),
pub layout: KomorebiLayout, pub layout: KomorebiLayout,
@@ -485,16 +487,16 @@ impl KomorebiNotificationState {
.unwrap_or_else(|| format!("{}", focused_workspace_idx + 1)); .unwrap_or_else(|| format!("{}", focused_workspace_idx + 1));
for (i, ws) in monitor.workspaces().iter().enumerate() { for (i, ws) in monitor.workspaces().iter().enumerate() {
let should_add = if self.hide_empty_workspaces { let should_show = if self.hide_empty_workspaces {
focused_workspace_idx == i || !ws.containers().is_empty() focused_workspace_idx == i || !ws.containers().is_empty()
} else { } else {
true true
}; };
if should_add { workspaces.push((
workspaces ws.name().to_owned().unwrap_or_else(|| format!("{}", i + 1)),
.push(ws.name().to_owned().unwrap_or_else(|| format!("{}", i + 1))); should_show,
} ));
} }
self.workspaces = workspaces; self.workspaces = workspaces;