mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-28 06:29:13 +02:00
fix(komorebi): account for border offset and width in layout
The layout should leave the space configured for the border, so that the border always stays within the workspace bounds. Border offset is cleaned up, as it is no longer a rect, but instead just a fixed value. The rect function for adjusting padding now takes a concrete value, as the optional has no local meaning to the operation, being equivalent to the default value. A margin function is added to centralize the notion of increasing the size of a rect by the given margin, the opposite of the padding operation.
This commit is contained in:
+2
-13
@@ -99,21 +99,10 @@ impl Border {
|
||||
}
|
||||
|
||||
let mut rect = WindowsApi::window_rect(window.hwnd())?;
|
||||
|
||||
let border_offset = BORDER_OFFSET.lock();
|
||||
if let Some(border_offset) = *border_offset {
|
||||
rect.left -= border_offset.left;
|
||||
rect.top -= border_offset.top;
|
||||
rect.right += border_offset.right;
|
||||
rect.bottom += border_offset.bottom;
|
||||
}
|
||||
rect.add_padding(-BORDER_OFFSET.load(Ordering::SeqCst));
|
||||
|
||||
let border_width = BORDER_WIDTH.load(Ordering::SeqCst);
|
||||
|
||||
rect.left -= border_width;
|
||||
rect.top -= border_width;
|
||||
rect.right += border_width * 2;
|
||||
rect.bottom += border_width * 2;
|
||||
rect.add_margin(border_width);
|
||||
|
||||
*BORDER_RECT.lock() = rect;
|
||||
|
||||
|
||||
+1
-2
@@ -192,8 +192,7 @@ lazy_static! {
|
||||
static ref BORDER_RECT: Arc<Mutex<Rect>> =
|
||||
Arc::new(Mutex::new(Rect::default()));
|
||||
|
||||
static ref BORDER_OFFSET: Arc<Mutex<Option<Rect>>> =
|
||||
Arc::new(Mutex::new(None));
|
||||
static ref BORDER_OFFSET: AtomicI32 = Default::default();
|
||||
|
||||
// Use app-specific titlebar removal options where possible
|
||||
// eg. Windows Terminal, IntelliJ IDEA, Firefox
|
||||
|
||||
@@ -1249,17 +1249,7 @@ impl WindowManager {
|
||||
WindowsApi::invalidate_border_rect()?;
|
||||
}
|
||||
SocketMessage::ActiveWindowBorderOffset(offset) => {
|
||||
let mut current_border_offset = BORDER_OFFSET.lock();
|
||||
|
||||
let new_border_offset = Rect {
|
||||
left: offset,
|
||||
top: offset,
|
||||
right: offset * 2,
|
||||
bottom: offset * 2,
|
||||
};
|
||||
|
||||
*current_border_offset = Option::from(new_border_offset);
|
||||
|
||||
BORDER_OFFSET.store(offset, Ordering::SeqCst);
|
||||
WindowsApi::invalidate_border_rect()?;
|
||||
}
|
||||
SocketMessage::AltFocusHack(enable) => {
|
||||
|
||||
@@ -378,9 +378,7 @@ impl From<&WindowManager> for StaticConfig {
|
||||
mouse_follows_focus: Option::from(value.mouse_follows_focus),
|
||||
app_specific_configuration_path: None,
|
||||
active_window_border_width: Option::from(BORDER_WIDTH.load(Ordering::SeqCst)),
|
||||
active_window_border_offset: BORDER_OFFSET
|
||||
.lock()
|
||||
.map_or(None, |offset| Option::from(offset.left)),
|
||||
active_window_border_offset: Option::from(BORDER_OFFSET.load(Ordering::SeqCst)),
|
||||
active_window_border: Option::from(BORDER_ENABLED.load(Ordering::SeqCst)),
|
||||
active_window_border_colours: border_colours,
|
||||
default_workspace_padding: Option::from(
|
||||
@@ -439,23 +437,8 @@ impl StaticConfig {
|
||||
BORDER_WIDTH.store(width, Ordering::SeqCst);
|
||||
},
|
||||
);
|
||||
self.active_window_border_offset.map_or_else(
|
||||
|| {
|
||||
let mut border_offset = BORDER_OFFSET.lock();
|
||||
*border_offset = None;
|
||||
},
|
||||
|offset| {
|
||||
let new_border_offset = Rect {
|
||||
left: offset,
|
||||
top: offset,
|
||||
right: offset * 2,
|
||||
bottom: offset * 2,
|
||||
};
|
||||
|
||||
let mut border_offset = BORDER_OFFSET.lock();
|
||||
*border_offset = Some(new_border_offset);
|
||||
},
|
||||
);
|
||||
BORDER_OFFSET.store(self.active_window_border_offset.unwrap_or_default(), Ordering::SeqCst);
|
||||
|
||||
if let Some(colours) = &self.active_window_border_colours {
|
||||
BORDER_COLOUR_SINGLE.store(u32::from(colours.single), Ordering::SeqCst);
|
||||
|
||||
@@ -26,6 +26,8 @@ use crate::static_config::WorkspaceConfig;
|
||||
use crate::window::Window;
|
||||
use crate::window::WindowDetails;
|
||||
use crate::windows_api::WindowsApi;
|
||||
use crate::BORDER_OFFSET;
|
||||
use crate::BORDER_WIDTH;
|
||||
use crate::DEFAULT_CONTAINER_PADDING;
|
||||
use crate::DEFAULT_WORKSPACE_PADDING;
|
||||
use crate::INITIAL_CONFIGURATION_LOADED;
|
||||
@@ -224,7 +226,7 @@ impl Workspace {
|
||||
},
|
||||
);
|
||||
|
||||
adjusted_work_area.add_padding(self.workspace_padding());
|
||||
adjusted_work_area.add_padding(self.workspace_padding().unwrap_or_default());
|
||||
|
||||
self.enforce_resize_constraints();
|
||||
|
||||
@@ -251,7 +253,13 @@ impl Workspace {
|
||||
if *self.tile() {
|
||||
if let Some(container) = self.monocle_container_mut() {
|
||||
if let Some(window) = container.focused_window_mut() {
|
||||
adjusted_work_area.add_padding(container_padding);
|
||||
adjusted_work_area.add_padding(container_padding.unwrap_or_default());
|
||||
{
|
||||
let border_offset = BORDER_OFFSET.load(Ordering::SeqCst);
|
||||
adjusted_work_area.add_padding(border_offset);
|
||||
let width = BORDER_WIDTH.load(Ordering::SeqCst);
|
||||
adjusted_work_area.add_padding(width);
|
||||
}
|
||||
window.set_position(&adjusted_work_area, true)?;
|
||||
};
|
||||
} else if let Some(window) = self.maximized_window_mut() {
|
||||
@@ -287,7 +295,16 @@ impl Workspace {
|
||||
WindowsApi::restore_window(window.hwnd());
|
||||
}
|
||||
|
||||
window.set_position(layout, false)?;
|
||||
let mut rect = *layout;
|
||||
{
|
||||
let border_offset = BORDER_OFFSET.load(Ordering::SeqCst);
|
||||
rect.add_padding(border_offset);
|
||||
|
||||
let width = BORDER_WIDTH.load(Ordering::SeqCst);
|
||||
rect.add_padding(width);
|
||||
}
|
||||
|
||||
window.set_position(&rect, false)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user