Skip to content

Commit

Permalink
fix(wm): fix focus changes with stackbar enabled
Browse files Browse the repository at this point in the history
Notify all stackbars on focus change, and they now respond to changes,
but do not create focus changes themselves just from an update.
  • Loading branch information
raggi authored and LGUG2Z committed Apr 14, 2024
1 parent 86b07f2 commit b476bee
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 62 deletions.
14 changes: 7 additions & 7 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ impl WindowManager {
);

self.focus_monitor(monitor_idx)?;
self.update_focused_workspace(self.mouse_follows_focus)?;
self.update_focused_workspace(self.mouse_follows_focus, true)?;
}
SocketMessage::FocusMonitorNumber(monitor_idx) => {
self.focus_monitor(monitor_idx)?;
self.update_focused_workspace(self.mouse_follows_focus)?;
self.update_focused_workspace(self.mouse_follows_focus, true)?;
}
SocketMessage::Retile => self.retile_all(false)?,
SocketMessage::FlipLayout(layout_flip) => self.flip_layout(layout_flip)?,
Expand Down Expand Up @@ -914,7 +914,7 @@ impl WindowManager {
}
}

self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
SocketMessage::FocusFollowsMouse(mut implementation, enable) => {
if !CUSTOM_FFM.load(Ordering::SeqCst) {
Expand Down Expand Up @@ -1020,7 +1020,7 @@ impl WindowManager {
SocketMessage::CompleteConfiguration => {
if !INITIAL_CONFIGURATION_LOADED.load(Ordering::SeqCst) {
INITIAL_CONFIGURATION_LOADED.store(true, Ordering::SeqCst);
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
}
SocketMessage::WatchConfiguration(enable) => {
Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl WindowManager {
let resize: Vec<Option<Rect>> = serde_json::from_reader(file)?;

workspace.set_resize_dimensions(resize);
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
SocketMessage::Save(ref path) => {
let workspace = self.focused_workspace_mut()?;
Expand All @@ -1150,7 +1150,7 @@ impl WindowManager {
let resize: Vec<Option<Rect>> = serde_json::from_reader(file)?;

workspace.set_resize_dimensions(resize);
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
SocketMessage::AddSubscriberSocket(ref socket) => {
let mut sockets = SUBSCRIPTION_SOCKETS.lock();
Expand Down Expand Up @@ -1295,7 +1295,7 @@ impl WindowManager {
SocketMessage::ToggleTitleBars => {
let current = REMOVE_TITLEBARS.load(Ordering::SeqCst);
REMOVE_TITLEBARS.store(!current, Ordering::SeqCst);
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
// Deprecated commands
SocketMessage::AltFocusHack(_)
Expand Down
33 changes: 20 additions & 13 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ impl WindowManager {
};

for (j, workspace) in monitor.workspaces_mut().iter_mut().enumerate() {
if let WindowManagerEvent::FocusChange(_, window) = event {
let _ = workspace.focus_changed(window.hwnd);
}

let reaped_orphans = workspace.reap_orphans()?;
if reaped_orphans.0 > 0 || reaped_orphans.1 > 0 {
workspace.update(&work_area, offset)?;
Expand All @@ -177,13 +181,12 @@ impl WindowManager {
}

match event {
WindowManagerEvent::Raise(window) => {
window.focus(false)?;
WindowManagerEvent::Raise(_window) => {
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)?;
self.update_focused_workspace(false, false)?;

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

Expand All @@ -201,7 +204,7 @@ impl WindowManager {

if hide {
self.focused_workspace_mut()?.remove_window(window.hwnd)?;
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
}
WindowManagerEvent::Hide(_, window) => {
Expand Down Expand Up @@ -242,14 +245,16 @@ impl WindowManager {

if hide {
self.focused_workspace_mut()?.remove_window(window.hwnd)?;
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}

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

already_moved_window_handles.remove(&window.hwnd);
}
WindowManagerEvent::FocusChange(_, window) => {
self.update_focused_workspace(true, false)?;

let workspace = self.focused_workspace_mut()?;
if !workspace
.floating_windows()
Expand Down Expand Up @@ -324,14 +329,14 @@ impl WindowManager {
match behaviour {
WindowContainerBehaviour::Create => {
workspace.new_container_for_window(window);
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
WindowContainerBehaviour::Append => {
workspace
.focused_container_mut()
.ok_or_else(|| anyhow!("there is no focused container"))?
.add_window(window);
self.update_focused_workspace(true)?;
self.update_focused_workspace(true, false)?;
}
}
}
Expand Down Expand Up @@ -481,11 +486,11 @@ impl WindowManager {
// the origin monitor's focused workspace
self.focus_monitor(origin_monitor_idx)?;
self.focus_workspace(origin_workspace_idx)?;
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;

self.focus_monitor(target_monitor_idx)?;
self.focus_workspace(target_workspace_idx)?;
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
// Here we handle a simple move on the same monitor which is treated as
// a container swap
Expand All @@ -496,11 +501,12 @@ impl WindowManager {
Some(target_idx) => {
workspace
.swap_containers(focused_container_idx, target_idx);
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
None => {
self.update_focused_workspace(
self.mouse_follows_focus,
false,
)?;
}
}
Expand All @@ -509,11 +515,12 @@ impl WindowManager {
match workspace.container_idx_from_current_point() {
Some(target_idx) => {
workspace.move_window_to_container(target_idx)?;
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
None => {
self.update_focused_workspace(
self.mouse_follows_focus,
false,
)?;
}
}
Expand Down Expand Up @@ -560,12 +567,12 @@ impl WindowManager {
self.resize_window(edge, sizing, delta, true)?;
}

self.update_focused_workspace(false)?;
self.update_focused_workspace(false, false)?;
}
}
}
WindowManagerEvent::ForceUpdate(_) => {
self.update_focused_workspace(false)?;
self.update_focused_workspace(false, true)?;
}
WindowManagerEvent::DisplayChange(..)
| WindowManagerEvent::MouseCapture(..)
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/stackbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ use komorebi_core::Rect;

use crate::window::Window;
use crate::windows_api::WindowsApi;
use crate::winevent_listener::event_tx;
use crate::WindowManagerEvent;
use crate::DEFAULT_CONTAINER_PADDING;
use crate::STACKBAR_FOCUSED_TEXT_COLOUR;
use crate::STACKBAR_TAB_BACKGROUND_COLOUR;
Expand Down Expand Up @@ -234,8 +236,6 @@ impl Stackbar {
for (i, window) in windows.iter().enumerate() {
if window.hwnd == focused_hwnd {
SetTextColor(hdc, COLORREF(focused_text_colour));

window.focus(false)?;
} else {
SetTextColor(hdc, COLORREF(unfocused_text_colour));
}
Expand Down
Loading

0 comments on commit b476bee

Please sign in to comment.