Skip to content

Commit

Permalink
feat(wm): immediate stackbar mode updates via ipc
Browse files Browse the repository at this point in the history
This commit ensures that when the stackbar mode is updated via a
SocketMessage or static config update, any visible stackbars will have
their mode updated immediately without having to wait for user
interaction.
  • Loading branch information
LGUG2Z committed Apr 16, 2024
1 parent 1671f31 commit 4615262
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 deletions.
14 changes: 14 additions & 0 deletions komorebi/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,18 @@ impl Container {
tracing::info!("focusing window");
self.windows.focus(idx);
}

pub fn set_stackbar_mode(&mut self, mode: StackbarMode) {
self.stackbar = match mode {
StackbarMode::Always => Stackbar::create().ok(),
StackbarMode::Never => None,
StackbarMode::OnStack => {
if self.windows().len() > 1 && self.stackbar().is_none() {
Stackbar::create().ok()
} else {
None
}
}
};
}
}
8 changes: 8 additions & 0 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,14 @@ impl WindowManager {
SocketMessage::StackbarMode(mode) => {
let mut stackbar_mode = STACKBAR_MODE.lock();
*stackbar_mode = mode;

for m in self.monitors_mut() {
for w in m.workspaces_mut() {
for c in w.containers_mut() {
c.set_stackbar_mode(mode);
}
}
}
}
SocketMessage::StackbarFocusedTextColour(r, g, b) => {
let rgb = Rgb::new(r, g, b);
Expand Down
10 changes: 6 additions & 4 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ impl WindowManager {
self.has_pending_raise_op = false;
}
WindowManagerEvent::Destroy(_, window) | WindowManagerEvent::Unmanage(window) => {
self.focused_workspace_mut()?.remove_window(window.hwnd)?;
self.update_focused_workspace(false, false)?;
if self.focused_workspace()?.contains_window(window.hwnd) {
self.focused_workspace_mut()?.remove_window(window.hwnd)?;
self.update_focused_workspace(false, false)?;

let mut already_moved_window_handles = self.already_moved_window_handles.lock();
let mut already_moved_window_handles = self.already_moved_window_handles.lock();

already_moved_window_handles.remove(&window.hwnd);
already_moved_window_handles.remove(&window.hwnd);
}
}
WindowManagerEvent::Minimize(_, window) => {
let mut hide = false;
Expand Down
12 changes: 12 additions & 0 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,12 @@ impl StaticConfig {
if let Some(height) = &stackbar.height {
STACKBAR_TAB_HEIGHT.store(*height, Ordering::SeqCst);
}

if let Some(mode) = &stackbar.mode {
let mut stackbar_mode = STACKBAR_MODE.lock();
*stackbar_mode = *mode;
}

if let Some(tabs) = &stackbar.tabs {
if let Some(background) = &tabs.background {
STACKBAR_TAB_BACKGROUND_COLOUR.store((*background).into(), Ordering::SeqCst);
Expand Down Expand Up @@ -725,6 +727,16 @@ impl StaticConfig {

value.apply_globals()?;

let stackbar_mode = STACKBAR_MODE.lock().clone();

for m in wm.monitors_mut() {
for w in m.workspaces_mut() {
for c in w.containers_mut() {
c.set_stackbar_mode(stackbar_mode);
}
}
}

if let Some(monitors) = value.monitors {
for (i, monitor) in monitors.iter().enumerate() {
if let Some(m) = wm.monitors_mut().get_mut(i) {
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl WindowsApi {
flags |= SetWindowPosition::NO_Z_ORDER;
}

let shadow_rect = Self::shadow_rect(hwnd)?;
let shadow_rect = Self::shadow_rect(hwnd).unwrap_or_default();
let rect = Rect {
left: layout.left + shadow_rect.left,
top: layout.top + shadow_rect.top,
Expand Down
18 changes: 9 additions & 9 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,17 @@ impl Workspace {
}

if let Some(stackbar) = container_topbar {
stackbar.set_position(
if let Ok(_) = stackbar.set_position(
&stackbar.get_position_from_container_layout(layout),
false,
)?;

stackbar.update(&container_windows, focused_hwnd)?;
let tab_height = STACKBAR_TAB_HEIGHT.load(Ordering::SeqCst);
let total_height = tab_height + container_padding;

rect.top += total_height;
rect.bottom -= total_height;
) {
stackbar.update(&container_windows, focused_hwnd)?;
let tab_height = STACKBAR_TAB_HEIGHT.load(Ordering::SeqCst);
let total_height = tab_height + container_padding;

rect.top += total_height;
rect.bottom -= total_height;
}
}

window.set_position(&rect, false)?;
Expand Down

0 comments on commit 4615262

Please sign in to comment.