mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-23 20:26:54 +02:00
feat(borders): permashow for floating windows
This commit leverages the z-ordering tracking of a border's target window to enable permanently showing borders for floating windows while applying different colours for focus state.
This commit is contained in:
@@ -305,7 +305,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
|
|
||||||
// Handle the monocle container separately
|
// Handle the monocle container separately
|
||||||
if let Some(monocle) = ws.monocle_container() {
|
if let Some(monocle) = ws.monocle_container() {
|
||||||
let mut new_border = false;
|
|
||||||
let border = match borders.entry(monocle.id().clone()) {
|
let border = match borders.entry(monocle.id().clone()) {
|
||||||
Entry::Occupied(entry) => entry.into_mut(),
|
Entry::Occupied(entry) => entry.into_mut(),
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
@@ -313,7 +312,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
monocle.id(),
|
monocle.id(),
|
||||||
monocle.focused_window().copied().unwrap_or_default().hwnd,
|
monocle.focused_window().copied().unwrap_or_default().hwnd,
|
||||||
) {
|
) {
|
||||||
new_border = true;
|
|
||||||
entry.insert(border)
|
entry.insert(border)
|
||||||
} else {
|
} else {
|
||||||
continue 'monitors;
|
continue 'monitors;
|
||||||
@@ -344,9 +342,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
|
|
||||||
let rect = WindowsApi::window_rect(reference_hwnd)?;
|
let rect = WindowsApi::window_rect(reference_hwnd)?;
|
||||||
|
|
||||||
if new_border {
|
|
||||||
border.set_position(&rect, reference_hwnd)?;
|
border.set_position(&rect, reference_hwnd)?;
|
||||||
}
|
|
||||||
|
|
||||||
border.invalidate();
|
border.invalidate();
|
||||||
|
|
||||||
@@ -420,7 +416,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
|
|
||||||
for (idx, c) in ws.containers().iter().enumerate() {
|
for (idx, c) in ws.containers().iter().enumerate() {
|
||||||
// Get the border entry for this container from the map or create one
|
// Get the border entry for this container from the map or create one
|
||||||
let mut new_border = false;
|
|
||||||
let border = match borders.entry(c.id().clone()) {
|
let border = match borders.entry(c.id().clone()) {
|
||||||
Entry::Occupied(entry) => entry.into_mut(),
|
Entry::Occupied(entry) => entry.into_mut(),
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
@@ -428,7 +423,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
c.id(),
|
c.id(),
|
||||||
c.focused_window().copied().unwrap_or_default().hwnd,
|
c.focused_window().copied().unwrap_or_default().hwnd,
|
||||||
) {
|
) {
|
||||||
new_border = true;
|
|
||||||
entry.insert(border)
|
entry.insert(border)
|
||||||
} else {
|
} else {
|
||||||
continue 'monitors;
|
continue 'monitors;
|
||||||
@@ -471,9 +465,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
Some(last_focus_state) => last_focus_state != new_focus_state,
|
Some(last_focus_state) => last_focus_state != new_focus_state,
|
||||||
};
|
};
|
||||||
|
|
||||||
if new_border {
|
|
||||||
border.set_position(&rect, reference_hwnd)?;
|
border.set_position(&rect, reference_hwnd)?;
|
||||||
}
|
|
||||||
|
|
||||||
if should_invalidate {
|
if should_invalidate {
|
||||||
border.invalidate();
|
border.invalidate();
|
||||||
@@ -481,15 +473,13 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
'windows: for window in ws.floating_windows() {
|
for window in ws.floating_windows() {
|
||||||
let mut new_border = false;
|
|
||||||
let border = match borders.entry(window.hwnd.to_string()) {
|
let border = match borders.entry(window.hwnd.to_string()) {
|
||||||
Entry::Occupied(entry) => entry.into_mut(),
|
Entry::Occupied(entry) => entry.into_mut(),
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
if let Ok(border) =
|
if let Ok(border) =
|
||||||
Border::create(&window.hwnd.to_string(), window.hwnd)
|
Border::create(&window.hwnd.to_string(), window.hwnd)
|
||||||
{
|
{
|
||||||
new_border = true;
|
|
||||||
entry.insert(border)
|
entry.insert(border)
|
||||||
} else {
|
} else {
|
||||||
continue 'monitors;
|
continue 'monitors;
|
||||||
@@ -500,30 +490,23 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
borders_monitors.insert(window.hwnd.to_string(), monitor_idx);
|
borders_monitors.insert(window.hwnd.to_string(), monitor_idx);
|
||||||
windows_borders.insert(window.hwnd, border.clone());
|
windows_borders.insert(window.hwnd, border.clone());
|
||||||
|
|
||||||
let mut should_destroy = false;
|
let mut is_focused = false;
|
||||||
|
|
||||||
if let Some(notification_hwnd) = notification.0 {
|
|
||||||
if notification_hwnd != window.hwnd {
|
|
||||||
should_destroy = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if WindowsApi::foreground_window().unwrap_or_default()
|
if WindowsApi::foreground_window().unwrap_or_default()
|
||||||
!= window.hwnd
|
== window.hwnd
|
||||||
{
|
{
|
||||||
should_destroy = true;
|
is_focused = true;
|
||||||
}
|
|
||||||
|
|
||||||
if should_destroy {
|
|
||||||
border.destroy()?;
|
|
||||||
borders.remove(&window.hwnd.to_string());
|
|
||||||
borders_monitors.remove(&window.hwnd.to_string());
|
|
||||||
continue 'windows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
let mut last_focus_state = None;
|
let mut last_focus_state = None;
|
||||||
let new_focus_state = WindowKind::Floating;
|
let new_focus_state = if is_focused {
|
||||||
|
WindowKind::Floating
|
||||||
|
} else {
|
||||||
|
WindowKind::Unfocused
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update the focused state for all containers on this workspace
|
||||||
{
|
{
|
||||||
let mut focus_state = FOCUS_STATE.lock();
|
let mut focus_state = FOCUS_STATE.lock();
|
||||||
last_focus_state =
|
last_focus_state =
|
||||||
@@ -537,9 +520,9 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
|||||||
Some(last_focus_state) => last_focus_state != new_focus_state,
|
Some(last_focus_state) => last_focus_state != new_focus_state,
|
||||||
};
|
};
|
||||||
|
|
||||||
if new_border {
|
// this has to be sent to match the z-order when clicking on
|
||||||
|
// a floating window to focus it
|
||||||
border.set_position(&rect, window.hwnd)?;
|
border.set_position(&rect, window.hwnd)?;
|
||||||
}
|
|
||||||
|
|
||||||
if should_invalidate {
|
if should_invalidate {
|
||||||
border.invalidate();
|
border.invalidate();
|
||||||
|
|||||||
Reference in New Issue
Block a user