Skip to content

Commit

Permalink
feat(borders): add windows accent implementation
Browse files Browse the repository at this point in the history
This commit adds the ability for users to select between komorebi's
implementation of borders with variable widths and the native Windows 11
implementation of thin "accent" borders.

The new border_implementation configuration option defaults to
BorderImplementation::Komorebi in order to preserve compat with existing
user configurations.

This option will be most useful for people who prefer ultra-thin
borders, and people who want borders to be animated along with
application windows if they are using the animation feature being worked
on in PR #685.
  • Loading branch information
LGUG2Z committed Jun 21, 2024
1 parent 9a65a4a commit 83272dd
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 205 deletions.
34 changes: 33 additions & 1 deletion komorebi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub enum SocketMessage {
BorderStyle(BorderStyle),
BorderWidth(i32),
BorderOffset(i32),
BorderImplementation(BorderImplementation),
Transparency(bool),
TransparencyAlpha(u8),
InvisibleBorders(Rect),
Expand Down Expand Up @@ -219,7 +220,17 @@ pub enum StackbarLabel {
}

#[derive(
Default, Copy, Clone, Debug, Eq, PartialEq, Display, Serialize, Deserialize, JsonSchema,
Default,
Copy,
Clone,
Debug,
Eq,
PartialEq,
Display,
Serialize,
Deserialize,
JsonSchema,
ValueEnum,
)]
pub enum BorderStyle {
#[default]
Expand All @@ -231,6 +242,27 @@ pub enum BorderStyle {
Square,
}

#[derive(
Default,
Copy,
Clone,
Debug,
Eq,
PartialEq,
Display,
Serialize,
Deserialize,
JsonSchema,
ValueEnum,
)]
pub enum BorderImplementation {
#[default]
/// Use the adjustable komorebi border implementation
Komorebi,
/// Use the thin Windows accent border implementation
Windows,
}

#[derive(
Copy,
Clone,
Expand Down
14 changes: 3 additions & 11 deletions komorebi/src/border_manager/border.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use crate::border_manager::window_kind_colour;
use crate::border_manager::WindowKind;
use crate::border_manager::BORDER_OFFSET;
use crate::border_manager::BORDER_WIDTH;
use crate::border_manager::FOCUSED;
use crate::border_manager::FOCUS_STATE;
use crate::border_manager::MONOCLE;
use crate::border_manager::STACK;
use crate::border_manager::STYLE;
use crate::border_manager::UNFOCUSED;
use crate::border_manager::Z_ORDER;
use crate::WindowsApi;
use crate::WINDOWS_11;
Expand Down Expand Up @@ -165,7 +162,7 @@ impl Border {
match WindowsApi::window_rect(window) {
Ok(rect) => {
// Grab the focus kind for this border
let focus_kind = {
let window_kind = {
FOCUS_STATE
.lock()
.get(&window.0)
Expand All @@ -177,12 +174,7 @@ impl Border {
let hpen = CreatePen(
PS_SOLID | PS_INSIDEFRAME,
BORDER_WIDTH.load(Ordering::SeqCst),
COLORREF(match focus_kind {
WindowKind::Unfocused => UNFOCUSED.load(Ordering::SeqCst),
WindowKind::Single => FOCUSED.load(Ordering::SeqCst),
WindowKind::Stack => STACK.load(Ordering::SeqCst),
WindowKind::Monocle => MONOCLE.load(Ordering::SeqCst),
}),
COLORREF(window_kind_colour(window_kind)),
);

let hbrush = WindowsApi::create_solid_brush(0);
Expand Down
Loading

0 comments on commit 83272dd

Please sign in to comment.