fix(bar): don't look up window titles at runtime

Doing runtime lookups via methods on Window in komorebi-bar won't work
because the AccessibilityObserver is not serialized and sent as part of
the notifications.

Instead, the notifications now take a snapshot of WindowDetails and
embed them so they can be read directly in komorebi-bar.
This commit is contained in:
LGUG2Z committed 2025-09-30 15:54:15 -07:00
1 parent 9777c55a1f
commit c3a756cbde
3 files changed
+20 -47

No files matched your search

+1 -1
View File
@@ -1004,7 +1004,7 @@ pub struct WindowInfo {
impl From<&Window> for WindowInfo {
fn from(value: &Window) -> Self {
Self {
title: value.title(),
title: value.details.as_ref().map(|details| details.title.clone()),
icon: None,
// icon: ImageIcon::try_load(value.hwnd, || {
// windows_icons::get_icon_by_hwnd(value.hwnd)
+12 -36
View File
@@ -43,7 +43,6 @@ use crate::window_manager_event::SystemNotification;
use crate::window_manager_event::WindowManagerEvent;
use crate::window_manager_event_listener;
use color_eyre::eyre;
use color_eyre::eyre::OptionExt;
use objc2::__framework_prelude::Retained;
use objc2_app_kit::NSApplicationActivationOptions;
use objc2_app_kit::NSRunningApplication;
@@ -184,10 +183,11 @@ pub struct Window {
pub application: Application,
#[serde(skip_deserializing)]
observer: AccessibilityObserver,
pub details: Option<WindowDetails>,
}
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct WindowDetails {
pub title: String,
pub exe: String,
@@ -195,16 +195,14 @@ pub struct WindowDetails {
pub subrole: String,
}
impl TryFrom<&Window> for WindowDetails {
type Error = eyre::ErrReport;
fn try_from(value: &Window) -> std::result::Result<Self, Self::Error> {
Ok(Self {
title: value.title().ok_or_eyre("can't read title")?,
exe: value.exe().ok_or_eyre("can't read exee")?,
role: value.role().ok_or_eyre("can't read role")?,
subrole: value.subrole().ok_or_eyre("can't read subrole")?,
})
impl From<&Window> for WindowDetails {
fn from(value: &Window) -> Self {
Self {
title: value.title().unwrap_or_default(),
exe: value.exe().unwrap_or_default(),
role: value.role().unwrap_or_default(),
subrole: value.subrole().unwrap_or_default(),
}
}
}
@@ -261,34 +259,11 @@ impl Serialize for Window {
{
let mut state = serializer.serialize_struct("Window", 6)?;
state.serialize_field("id", &self.id)?;
state.serialize_field(
"title",
&self
.title()
.unwrap_or_else(|| String::from("could not get window title")),
)?;
state.serialize_field(
"exe",
&self
.exe()
.unwrap_or_else(|| String::from("could not get window exe")),
)?;
state.serialize_field(
"role",
&self
.role()
.unwrap_or_else(|| String::from("could not get window accessibility role")),
)?;
state.serialize_field(
"subrole",
&self
.subrole()
.unwrap_or_else(|| String::from("could not get window accessibility subrole")),
)?;
state.serialize_field(
"rect",
&Rect::from(MacosApi::window_rect(&self.element).unwrap_or_default()),
)?;
state.serialize_field("details", &WindowDetails::from(self))?;
state.end()
}
}
@@ -331,6 +306,7 @@ impl Window {
element: AccessibilityUiElement(element),
application,
observer: AccessibilityObserver(Some(observer)),
details: None,
})
}
+7 -10
View File
@@ -975,31 +975,28 @@ impl Workspace {
pub fn visible_window_details(&self) -> Vec<WindowDetails> {
let mut vec: Vec<WindowDetails> = vec![];
if let Some(maximized) = &self.maximized_window
&& let Ok(details) = (maximized).try_into()
{
if let Some(maximized) = &self.maximized_window {
let details = maximized.into();
vec.push(details);
}
if let Some(monocle) = &self.monocle_container
&& let Some(focused) = monocle.focused_window()
&& let Ok(details) = focused.try_into()
{
let details = focused.into();
vec.push(details);
}
for container in self.containers() {
if let Some(focused) = container.focused_window()
&& let Ok(details) = focused.try_into()
{
if let Some(focused) = container.focused_window() {
let details = focused.into();
vec.push(details);
}
}
for window in self.floating_windows() {
if let Ok(details) = window.try_into() {
vec.push(details);
}
let details = window.into();
vec.push(details);
}
vec