feat(bar): render at notch level on macbooks

This commit uses raw-window-handle to access the NSWindow of the bar and
set the window level to `kCGBackstopMenuLevel` (-20), positioning the
bar behind the menu bar, and at the same level as the notch on Macbook
screens.

This approach means the bar occupies space already excluded from the
work area by the menu bar, so the automatic work area offset calculation
is no longer needed and has been commented out. (I think... Need to
validate this on regular non-Macbook external displays...)

The explicit user-configured `work_area_offset` option is preserved for
users who want more flexibility.
This commit is contained in:
LGUG2Z committed 2026-01-03 10:13:17 -08:00
1 parent 6b52e4b3a4
commit ca94a57dd5
6 files changed
+93 -67

No files matched your search

Generated
+1
View File
@@ -3069,6 +3069,7 @@ dependencies = [
"objc2-app-kit 0.3.2",
"parking_lot",
"random_word",
"raw-window-handle",
"reqwest",
"schemars 1.2.0",
"serde",
+21 -21
View File
@@ -43,14 +43,14 @@
"block-buffer 0.10.4 registry+https://github.com/rust-lang/crates.io-index",
"bytemuck 1.24.0 registry+https://github.com/rust-lang/crates.io-index",
"bytemuck_derive 1.10.2 registry+https://github.com/rust-lang/crates.io-index",
"cc 1.2.50 registry+https://github.com/rust-lang/crates.io-index",
"cc 1.2.51 registry+https://github.com/rust-lang/crates.io-index",
"cfg-if 1.0.4 registry+https://github.com/rust-lang/crates.io-index",
"cgl 0.3.2 registry+https://github.com/rust-lang/crates.io-index",
"chrono 0.4.42 registry+https://github.com/rust-lang/crates.io-index",
"chrono-tz 0.10.4 registry+https://github.com/rust-lang/crates.io-index",
"clap 4.5.53 registry+https://github.com/rust-lang/crates.io-index",
"clap_builder 4.5.53 registry+https://github.com/rust-lang/crates.io-index",
"clap_complete 4.5.62 registry+https://github.com/rust-lang/crates.io-index",
"clap_complete 4.5.64 registry+https://github.com/rust-lang/crates.io-index",
"clap_derive 4.5.49 registry+https://github.com/rust-lang/crates.io-index",
"clap_lex 0.7.6 registry+https://github.com/rust-lang/crates.io-index",
"color-eyre 0.6.5 registry+https://github.com/rust-lang/crates.io-index",
@@ -105,7 +105,7 @@
"fastrand 2.3.0 registry+https://github.com/rust-lang/crates.io-index",
"fdeflate 0.3.7 registry+https://github.com/rust-lang/crates.io-index",
"filetime 0.2.26 registry+https://github.com/rust-lang/crates.io-index",
"find-msvc-tools 0.1.5 registry+https://github.com/rust-lang/crates.io-index",
"find-msvc-tools 0.1.6 registry+https://github.com/rust-lang/crates.io-index",
"flate2 1.1.5 registry+https://github.com/rust-lang/crates.io-index",
"fnv 1.0.7 registry+https://github.com/rust-lang/crates.io-index",
"foreign-types 0.3.2 registry+https://github.com/rust-lang/crates.io-index",
@@ -151,11 +151,11 @@
"indexmap 1.9.3 registry+https://github.com/rust-lang/crates.io-index",
"indexmap 2.12.1 registry+https://github.com/rust-lang/crates.io-index",
"ipnet 2.11.0 registry+https://github.com/rust-lang/crates.io-index",
"iri-string 0.7.9 registry+https://github.com/rust-lang/crates.io-index",
"iri-string 0.7.10 registry+https://github.com/rust-lang/crates.io-index",
"is_debug 1.1.0 registry+https://github.com/rust-lang/crates.io-index",
"is_terminal_polyfill 1.70.2 registry+https://github.com/rust-lang/crates.io-index",
"itertools 0.14.0 registry+https://github.com/rust-lang/crates.io-index",
"itoa 1.0.16 registry+https://github.com/rust-lang/crates.io-index",
"itoa 1.0.17 registry+https://github.com/rust-lang/crates.io-index",
"jobserver 0.1.34 registry+https://github.com/rust-lang/crates.io-index",
"jpeg-decoder 0.1.22 registry+https://github.com/rust-lang/crates.io-index",
"lazy_static 1.5.0 registry+https://github.com/rust-lang/crates.io-index",
@@ -214,7 +214,7 @@
"png 0.18.0 registry+https://github.com/rust-lang/crates.io-index",
"powerfmt 0.2.0 registry+https://github.com/rust-lang/crates.io-index",
"ppv-lite86 0.2.21 registry+https://github.com/rust-lang/crates.io-index",
"proc-macro2 1.0.103 registry+https://github.com/rust-lang/crates.io-index",
"proc-macro2 1.0.104 registry+https://github.com/rust-lang/crates.io-index",
"profiling 1.0.17 registry+https://github.com/rust-lang/crates.io-index",
"profiling-procmacros 1.0.17 registry+https://github.com/rust-lang/crates.io-index",
"pxfm 0.1.27 registry+https://github.com/rust-lang/crates.io-index",
@@ -244,7 +244,7 @@
"rustc_version 0.4.1 registry+https://github.com/rust-lang/crates.io-index",
"rustix 1.1.3 registry+https://github.com/rust-lang/crates.io-index",
"rustls-pki-types 1.13.2 registry+https://github.com/rust-lang/crates.io-index",
"ryu 1.0.21 registry+https://github.com/rust-lang/crates.io-index",
"ryu 1.0.22 registry+https://github.com/rust-lang/crates.io-index",
"scopeguard 1.2.0 registry+https://github.com/rust-lang/crates.io-index",
"security-framework 2.11.1 registry+https://github.com/rust-lang/crates.io-index",
"security-framework-sys 2.15.0 registry+https://github.com/rust-lang/crates.io-index",
@@ -253,7 +253,7 @@
"serde_core 1.0.228 registry+https://github.com/rust-lang/crates.io-index",
"serde_derive 1.0.228 registry+https://github.com/rust-lang/crates.io-index",
"serde_derive_internals 0.29.1 registry+https://github.com/rust-lang/crates.io-index",
"serde_json 1.0.147 registry+https://github.com/rust-lang/crates.io-index",
"serde_json 1.0.148 registry+https://github.com/rust-lang/crates.io-index",
"serde_json_lenient 0.2.4 registry+https://github.com/rust-lang/crates.io-index",
"serde_urlencoded 0.7.1 registry+https://github.com/rust-lang/crates.io-index",
"serde_variant 0.1.3 registry+https://github.com/rust-lang/crates.io-index",
@@ -274,7 +274,7 @@
"stable_deref_trait 1.2.1 registry+https://github.com/rust-lang/crates.io-index",
"static_assertions 1.1.0 registry+https://github.com/rust-lang/crates.io-index",
"syn 1.0.109 registry+https://github.com/rust-lang/crates.io-index",
"syn 2.0.111 registry+https://github.com/rust-lang/crates.io-index",
"syn 2.0.112 registry+https://github.com/rust-lang/crates.io-index",
"sync_wrapper 1.0.2 registry+https://github.com/rust-lang/crates.io-index",
"system-configuration 0.6.1 registry+https://github.com/rust-lang/crates.io-index",
"system-configuration-sys 0.6.0 registry+https://github.com/rust-lang/crates.io-index",
@@ -362,7 +362,7 @@
[
"BSL-1.0",
[
"ryu 1.0.21 registry+https://github.com/rust-lang/crates.io-index"
"ryu 1.0.22 registry+https://github.com/rust-lang/crates.io-index"
]
],
[
@@ -429,7 +429,7 @@
"calm_io 0.1.1 registry+https://github.com/rust-lang/crates.io-index",
"calmio_filters 0.1.0 registry+https://github.com/rust-lang/crates.io-index",
"catppuccin-egui 5.6.0 git+https://github.com/LGUG2Z/catppuccin-egui?rev=b2f95cbf441d1dd99f3c955ef10dcb84ce23c20a",
"cc 1.2.50 registry+https://github.com/rust-lang/crates.io-index",
"cc 1.2.51 registry+https://github.com/rust-lang/crates.io-index",
"cfg-if 1.0.4 registry+https://github.com/rust-lang/crates.io-index",
"cfg_aliases 0.2.1 registry+https://github.com/rust-lang/crates.io-index",
"cgl 0.3.2 registry+https://github.com/rust-lang/crates.io-index",
@@ -437,7 +437,7 @@
"chrono-tz 0.10.4 registry+https://github.com/rust-lang/crates.io-index",
"clap 4.5.53 registry+https://github.com/rust-lang/crates.io-index",
"clap_builder 4.5.53 registry+https://github.com/rust-lang/crates.io-index",
"clap_complete 4.5.62 registry+https://github.com/rust-lang/crates.io-index",
"clap_complete 4.5.64 registry+https://github.com/rust-lang/crates.io-index",
"clap_derive 4.5.49 registry+https://github.com/rust-lang/crates.io-index",
"clap_lex 0.7.6 registry+https://github.com/rust-lang/crates.io-index",
"color-eyre 0.6.5 registry+https://github.com/rust-lang/crates.io-index",
@@ -501,7 +501,7 @@
"fax_derive 0.2.0 registry+https://github.com/rust-lang/crates.io-index",
"fdeflate 0.3.7 registry+https://github.com/rust-lang/crates.io-index",
"filetime 0.2.26 registry+https://github.com/rust-lang/crates.io-index",
"find-msvc-tools 0.1.5 registry+https://github.com/rust-lang/crates.io-index",
"find-msvc-tools 0.1.6 registry+https://github.com/rust-lang/crates.io-index",
"flate2 1.1.5 registry+https://github.com/rust-lang/crates.io-index",
"flavours 0.7.2 git+https://github.com/LGUG2Z/flavours",
"fnv 1.0.7 registry+https://github.com/rust-lang/crates.io-index",
@@ -558,11 +558,11 @@
"indexmap 1.9.3 registry+https://github.com/rust-lang/crates.io-index",
"indexmap 2.12.1 registry+https://github.com/rust-lang/crates.io-index",
"ipnet 2.11.0 registry+https://github.com/rust-lang/crates.io-index",
"iri-string 0.7.9 registry+https://github.com/rust-lang/crates.io-index",
"iri-string 0.7.10 registry+https://github.com/rust-lang/crates.io-index",
"is_debug 1.1.0 registry+https://github.com/rust-lang/crates.io-index",
"is_terminal_polyfill 1.70.2 registry+https://github.com/rust-lang/crates.io-index",
"itertools 0.14.0 registry+https://github.com/rust-lang/crates.io-index",
"itoa 1.0.16 registry+https://github.com/rust-lang/crates.io-index",
"itoa 1.0.17 registry+https://github.com/rust-lang/crates.io-index",
"jobserver 0.1.34 registry+https://github.com/rust-lang/crates.io-index",
"jpeg-decoder 0.1.22 registry+https://github.com/rust-lang/crates.io-index",
"lazy_static 1.5.0 registry+https://github.com/rust-lang/crates.io-index",
@@ -650,7 +650,7 @@
"png 0.18.0 registry+https://github.com/rust-lang/crates.io-index",
"powerfmt 0.2.0 registry+https://github.com/rust-lang/crates.io-index",
"ppv-lite86 0.2.21 registry+https://github.com/rust-lang/crates.io-index",
"proc-macro2 1.0.103 registry+https://github.com/rust-lang/crates.io-index",
"proc-macro2 1.0.104 registry+https://github.com/rust-lang/crates.io-index",
"profiling 1.0.17 registry+https://github.com/rust-lang/crates.io-index",
"profiling-procmacros 1.0.17 registry+https://github.com/rust-lang/crates.io-index",
"qoi 0.4.1 registry+https://github.com/rust-lang/crates.io-index",
@@ -685,8 +685,8 @@
"rustix 1.1.3 registry+https://github.com/rust-lang/crates.io-index",
"rustls-pki-types 1.13.2 registry+https://github.com/rust-lang/crates.io-index",
"same-file 1.0.6 registry+https://github.com/rust-lang/crates.io-index",
"schemars 1.1.0 registry+https://github.com/rust-lang/crates.io-index",
"schemars_derive 1.1.0 registry+https://github.com/rust-lang/crates.io-index",
"schemars 1.2.0 registry+https://github.com/rust-lang/crates.io-index",
"schemars_derive 1.2.0 registry+https://github.com/rust-lang/crates.io-index",
"scoped_threadpool 0.1.9 registry+https://github.com/rust-lang/crates.io-index",
"scopeguard 1.2.0 registry+https://github.com/rust-lang/crates.io-index",
"security-framework 2.11.1 registry+https://github.com/rust-lang/crates.io-index",
@@ -696,7 +696,7 @@
"serde_core 1.0.228 registry+https://github.com/rust-lang/crates.io-index",
"serde_derive 1.0.228 registry+https://github.com/rust-lang/crates.io-index",
"serde_derive_internals 0.29.1 registry+https://github.com/rust-lang/crates.io-index",
"serde_json 1.0.147 registry+https://github.com/rust-lang/crates.io-index",
"serde_json 1.0.148 registry+https://github.com/rust-lang/crates.io-index",
"serde_json_lenient 0.2.4 registry+https://github.com/rust-lang/crates.io-index",
"serde_urlencoded 0.7.1 registry+https://github.com/rust-lang/crates.io-index",
"serde_variant 0.1.3 registry+https://github.com/rust-lang/crates.io-index",
@@ -724,7 +724,7 @@
"strum 0.27.2 registry+https://github.com/rust-lang/crates.io-index",
"strum_macros 0.27.2 registry+https://github.com/rust-lang/crates.io-index",
"syn 1.0.109 registry+https://github.com/rust-lang/crates.io-index",
"syn 2.0.111 registry+https://github.com/rust-lang/crates.io-index",
"syn 2.0.112 registry+https://github.com/rust-lang/crates.io-index",
"synstructure 0.13.2 registry+https://github.com/rust-lang/crates.io-index",
"sysinfo 0.37.2 registry+https://github.com/rust-lang/crates.io-index",
"system-configuration 0.6.1 registry+https://github.com/rust-lang/crates.io-index",
@@ -778,7 +778,7 @@
"zerocopy 0.8.31 registry+https://github.com/rust-lang/crates.io-index",
"zerocopy-derive 0.8.31 registry+https://github.com/rust-lang/crates.io-index",
"zeroize 1.8.2 registry+https://github.com/rust-lang/crates.io-index",
"zmij 0.1.7 registry+https://github.com/rust-lang/crates.io-index",
"zmij 1.0.6 registry+https://github.com/rust-lang/crates.io-index",
"zune-core 0.4.12 registry+https://github.com/rust-lang/crates.io-index",
"zune-core 0.5.0 registry+https://github.com/rust-lang/crates.io-index",
"zune-inflate 0.2.54 registry+https://github.com/rust-lang/crates.io-index",
+1 -1
View File
@@ -2,7 +2,7 @@
"$schema": "https://komorebi-for-mac.lgug2z.com/komorebi.bar.0.1.0.schema.json",
"monitor": 0,
"font_family": "JetBrainsMono Nerd Font",
"height": 30,
"height": 40,
"theme": {
"palette": "Base16",
"name": "Ashes",
+4
View File
@@ -31,7 +31,11 @@ objc2 = { version = "0.6", default-features = false, features = ["std"] }
objc2-app-kit = { version = "0.3", default-features = false, features = [
"std",
"NSApplication",
"NSResponder",
"NSView",
"NSWindow",
] }
raw-window-handle = "0.6"
parking_lot = { workspace = true }
random_word = { version = "0.5", features = ["en"] }
reqwest = { version = "0.12", features = ["blocking"] }
+48 -45
View File
@@ -465,54 +465,57 @@ impl Komobar {
if let Some(monitor_index) = self.monitor_index {
if let (prev_rect, Some(new_rect)) = (&self.work_area_offset, &config_work_area_offset)
&& new_rect != prev_rect
{
if new_rect != prev_rect {
self.work_area_offset = *new_rect;
if let Err(error) = komorebi_client::send_message(
&SocketMessage::MonitorWorkAreaOffset(monitor_index, *new_rect),
) {
tracing::error!(
"error applying work area offset to monitor '{}': {}",
monitor_index,
error,
);
} else {
tracing::info!("work area offset applied to monitor: {}", monitor_index);
}
}
} else if let Some(height) = self.config.height.or(Some(BAR_HEIGHT)) {
// We only add the `bottom_margin` to the work_area_offset since the top margin is
// already considered on the `size_rect.top`
let bottom_margin = self
.config
.margin
.as_ref()
.map_or(0, |v| v.to_individual(0.0).bottom as i32);
let new_rect = komorebi_client::Rect {
left: 0,
top: (height as i32)
+ (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
+ bottom_margin,
right: 0,
bottom: (height as i32)
+ (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
+ bottom_margin,
};
if new_rect != self.work_area_offset {
self.work_area_offset = new_rect;
if let Err(error) = komorebi_client::send_message(
&SocketMessage::MonitorWorkAreaOffset(monitor_index, new_rect),
) {
tracing::error!(
"error applying work area offset to monitor '{monitor_index}': {error}"
);
} else {
tracing::info!("work area offset applied to monitor: {monitor_index}",);
}
self.work_area_offset = *new_rect;
if let Err(error) = komorebi_client::send_message(
&SocketMessage::MonitorWorkAreaOffset(monitor_index, *new_rect),
) {
tracing::error!(
"error applying work area offset to monitor '{}': {}",
monitor_index,
error,
);
} else {
tracing::info!("work area offset applied to monitor: {}", monitor_index);
}
}
// TODO: Not sure if we need this now that we are drawing behind the notch
// TODO: Also need to figure out how this looks on external monitors
// TODO: Probably not going to support other positions on macOS
// else if let Some(height) = self.config.height.or(Some(BAR_HEIGHT)) {
// // We only add the `bottom_margin` to the work_area_offset since the top margin is
// // already considered on the `size_rect.top`
// let bottom_margin = self
// .config
// .margin
// .as_ref()
// .map_or(0, |v| v.to_individual(0.0).bottom as i32);
// let new_rect = komorebi_client::Rect {
// left: 0,
// top: (height as i32)
// + (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
// + bottom_margin,
// right: 0,
// bottom: (height as i32)
// + (self.size_rect.top - MONITOR_TOP.load(Ordering::SeqCst))
// + bottom_margin,
// };
// if new_rect != self.work_area_offset {
// self.work_area_offset = new_rect;
// if let Err(error) = komorebi_client::send_message(
// &SocketMessage::MonitorWorkAreaOffset(monitor_index, new_rect),
// ) {
// tracing::error!(
// "error applying work area offset to monitor '{monitor_index}': {error}"
// );
// } else {
// tracing::info!("work area offset applied to monitor: {monitor_index}",);
// }
// }
// }
} else if self.monitor_info.is_some() && !self.disabled {
tracing::warn!(
"couldn't find the monitor index of this bar! Disabling the bar until the monitor connects..."
+18
View File
@@ -23,6 +23,9 @@ use komorebi_client::replace_env_in_path;
use objc2::MainThreadMarker;
use objc2_app_kit::NSApplication;
use objc2_app_kit::NSApplicationActivationPolicy;
use objc2_app_kit::NSView;
use raw_window_handle::HasWindowHandle;
use raw_window_handle::RawWindowHandle;
use std::io::BufReader;
use std::io::Read;
use std::path::PathBuf;
@@ -210,6 +213,8 @@ fn main() -> eyre::Result<()> {
MONITOR_INDEX.store(monitor_index, Ordering::SeqCst);
// use monitor.size for the actual monitor bounds (top-left origin in global coordinates)
// the window level kCGBackstopMenuLevel positions the bar behind the menu bar
match config.position {
None => {
config.position = Some(PositionConfig {
@@ -289,6 +294,19 @@ fn main() -> eyre::Result<()> {
app.setActivationPolicy(NSApplicationActivationPolicy::Accessory);
}
if let Ok(handle) = cc.window_handle()
&& let RawWindowHandle::AppKit(appkit_handle) = handle.as_raw() {
// kCGBackstopMenuLevel = -20 (behind menu bar, at notch level)
const K_CG_BACKSTOP_MENU_LEVEL: isize = -20;
unsafe {
let ns_view: &NSView = appkit_handle.ns_view.cast().as_ref();
if let Some(ns_window) = ns_view.window() {
ns_window.setLevel(K_CG_BACKSTOP_MENU_LEVEL);
}
}
}
let ctx_repainter = cc.egui_ctx.clone();
std::thread::spawn(move || loop {
std::thread::sleep(Duration::from_secs(1));