mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-18 22:58:34 +01:00
feat(windowtrack): mark komoborder windows and list them on Windows
This commit is contained in:
1 parent
ca6a6380c5
commit
f945442c52
7 files changed
+99
-5
No files matched your search
@@ -36,7 +36,7 @@
|
||||
//! With [`SheetOptions::windows`] (the `--windows` flag), each frame also has the rect of every
|
||||
//! window drawn on it, from the session's window track (see [`super::window_track`]): a 2 pixel
|
||||
//! border in a colour taken from the window's id and a label of the owner and id, front windows
|
||||
//! drawn last. Windows that are minimized or not visible are not drawn; a cloaked window (Windows
|
||||
//! drawn last. Windows that are minimized or not visible, and komorebi's borders (`border`), are not drawn; a cloaked window (Windows
|
||||
//! only: hidden but still "visible") has a thin dim border, so that a window komorebi has hidden
|
||||
//! can be told from one that is shown. The windows are those of the moment of the picture
|
||||
//! shown, which is how [`SheetFrame::windows`] names them. [`rect_in_cell`] is the conversion from
|
||||
@@ -394,7 +394,8 @@ impl Canvas {
|
||||
) -> Vec<u32> {
|
||||
let mut drawn = Vec::new();
|
||||
for window in windows.iter().rev() {
|
||||
if !window.visible || window.minimized {
|
||||
// a border is a thin frame right around its window: drawn, it would hide it
|
||||
if !window.visible || window.minimized || window.border {
|
||||
continue;
|
||||
}
|
||||
let Some([left, top, w, h]) = rect_in_cell(window.rect, frame, width, height) else {
|
||||
|
||||
@@ -41,6 +41,8 @@ fn sample(window: &Window, visible: bool) -> Option<WindowSample> {
|
||||
visible,
|
||||
minimized: false,
|
||||
cloaked: None,
|
||||
border: false,
|
||||
border_of: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -187,6 +187,8 @@ pub fn window_list() -> Vec<WindowSample> {
|
||||
visible: onscreen.unwrap_or(false),
|
||||
minimized: false,
|
||||
cloaked: None,
|
||||
border: false,
|
||||
border_of: None,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ use windows::Win32::Graphics::Dwm::DwmGetWindowAttribute;
|
||||
use windows::Win32::System::Threading::GetCurrentProcessId;
|
||||
use windows::Win32::UI::WindowsAndMessaging::EnumWindows;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GWL_EXSTYLE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetClassNameW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowLongW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowRect;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowTextW;
|
||||
@@ -181,7 +182,8 @@ fn program_of(pid: u32) -> String {
|
||||
/// `EnumWindows` pass, then a few cheap reads of each window.
|
||||
///
|
||||
/// Left out: windows that are not visible (`IsWindowVisible`), tool windows (`WS_EX_TOOLWINDOW`:
|
||||
/// tooltips, toasts, floating palettes), windows with an empty frame, and this process's own
|
||||
/// tooltips, toasts, floating palettes) except komorebi's borders (class `komoborder-<id>`, listed
|
||||
/// with `border` true, see [`WindowSample::border`]), windows with an empty frame, and this process's own
|
||||
/// windows (the recorder and the viewer are not in the video either). The rect is the visible
|
||||
/// frame, as [`inspect`] reads it. A cloaked window (another virtual desktop, or hidden by
|
||||
/// komorebi) is listed with `cloaked` true. The program name is looked up once for each process
|
||||
@@ -202,8 +204,18 @@ pub fn list() -> Vec<WindowSample> {
|
||||
if !IsWindowVisible(window).as_bool() {
|
||||
continue;
|
||||
}
|
||||
// komorebi's borders are tool windows too, and are kept: they are what the track is
|
||||
// asked about when a border has fallen behind its window
|
||||
let mut border = None;
|
||||
if GetWindowLongW(window, GWL_EXSTYLE) as u32 & WS_EX_TOOLWINDOW.0 != 0 {
|
||||
continue;
|
||||
let mut class = [0_u16; 128];
|
||||
let length = GetClassNameW(window, &mut class).max(0) as usize;
|
||||
border = crate::sources::windowtrack::border_class(&String::from_utf16_lossy(
|
||||
&class[..length.min(class.len())],
|
||||
));
|
||||
if border.is_none() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let mut pid = 0_u32;
|
||||
GetWindowThreadProcessId(window, Some(&raw mut pid));
|
||||
@@ -246,6 +258,8 @@ pub fn list() -> Vec<WindowSample> {
|
||||
visible: true,
|
||||
minimized: IsIconic(window).as_bool(),
|
||||
cloaked: Some(cloaked != 0),
|
||||
border: border.is_some(),
|
||||
border_of: border.flatten(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,7 +546,7 @@ pub fn readme(dir: &Path, manifest: &Manifest) -> String {
|
||||
"| `state-start.json`, `state-end.json` | `State` when recording started / stopped |\n",
|
||||
);
|
||||
if manifest.window_track.is_some() {
|
||||
out.push_str("| `windows.jsonl` | The window track: every top-level window's rect and state, front to back, written when something changed and in full once a second: `{mach_ns, key?, windows: [{id, owner, title?, rect: [l,t,r,b], visible, minimized, cloaked?}]}`. `sheet --windows` draws it on frames |
|
||||
out.push_str("| `windows.jsonl` | The window track: every top-level window's rect and state, front to back, written when something changed and in full once a second: `{mach_ns, key?, windows: [{id, owner, title?, rect: [l,t,r,b], visible, minimized, cloaked?, border?, border_of?}]}`; `border` marks komorebi's own border windows (Windows). `sheet --windows` draws it on frames |
|
||||
");
|
||||
}
|
||||
out.push_str(os_trace_rows(&host));
|
||||
|
||||
@@ -30,6 +30,20 @@
|
||||
//! macOS. Both are the units of a display's `frame` in `session.json`, which is how the `sheet
|
||||
//! --windows` overlay places them on a frame. `cloaked` is `null` or absent on macOS.
|
||||
//!
|
||||
//! # Borders
|
||||
//!
|
||||
//! komorebi for Windows draws each border as a top-level window of its own (class and title
|
||||
//! `komoborder-<id>`, a topmost tool window). Those are kept in the track, marked `"border":true`,
|
||||
//! so a reader can ask whether a border was N px off its window at time T. When the border is
|
||||
//! named for a window (a floating window's border is `komoborder-<hwnd>`), `"border_of"` is that
|
||||
//! handle. A tiled or monocle container's border is named for the *container* (a UUID, in the
|
||||
//! border's `title`), which komorebi's `State` maps to the container's focused window: that join
|
||||
//! is exact but is the analysis's to make; when the container id is not enough (or the state is
|
||||
//! missing), pairing a border with a window by rect and z-order is a heuristic and is not done
|
||||
//! here. Neither field is ever guessed. macOS komorebi has no such windows this crate knows of
|
||||
//! (any border window there is not layer 0, which the Mac listing leaves out), and komorebi for KDE
|
||||
//! draws no border windows at all: KWin's rounded-corners effect paints them.
|
||||
//!
|
||||
//! # Threads and cost
|
||||
//!
|
||||
//! A [`WindowTracker`] owns one thread (`window-track`) that owns the file, as the event recorder's
|
||||
@@ -53,6 +67,8 @@
|
||||
//! visible: true,
|
||||
//! minimized: false,
|
||||
//! cloaked: Some(false),
|
||||
//! border: false,
|
||||
//! border_of: None,
|
||||
//! };
|
||||
//!
|
||||
//! let mut filter = ChangeFilter::default();
|
||||
@@ -115,6 +131,20 @@ pub struct WindowSample {
|
||||
/// still "visible"). `None` where the host has no such thing (a Mac).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub cloaked: Option<bool>,
|
||||
/// Whether this is one of komorebi's own border windows (on Windows, a top-level window of
|
||||
/// class `komoborder-<id>`), which komorebi draws around a window as a window of its own. A
|
||||
/// reader asks "is the border N px off its window at time T" by comparing the rect of a
|
||||
/// border with the rect of the window it belongs to. Absent when false.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub border: bool,
|
||||
/// For a border, the id of the window it was drawn for, when the border says so by itself: the
|
||||
/// border of a floating window is named for that window's handle (`komoborder-<hwnd>`), so this
|
||||
/// is exact. The border of a tiled or monocle container is named for the container (a UUID),
|
||||
/// which is *not* a window: it is in `title`, and the pairing with a window goes through the
|
||||
/// container ids of `State` (its focused window). Absent otherwise; it is never guessed from
|
||||
/// rects.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub border_of: Option<u32>,
|
||||
}
|
||||
|
||||
impl WindowSample {
|
||||
@@ -127,6 +157,8 @@ impl WindowSample {
|
||||
&& self.visible == other.visible
|
||||
&& self.minimized == other.minimized
|
||||
&& self.cloaked == other.cloaked
|
||||
&& self.border == other.border
|
||||
&& self.border_of == other.border_of
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +174,26 @@ pub struct TrackRow {
|
||||
pub windows: Vec<WindowSample>,
|
||||
}
|
||||
|
||||
/// What a window class says about komorebi's borders: `None` if it is not a border's class, else
|
||||
/// `Some(window)` where `window` is the handle the border is named for, if it is named for one.
|
||||
///
|
||||
/// komorebi for Windows names a border's class and title `komoborder-<id>`, where `<id>` is the
|
||||
/// container's id (a UUID) for a tiled or monocle container and the window's handle in decimal for
|
||||
/// a floating window.
|
||||
///
|
||||
/// ```rust
|
||||
/// use komorebi_recorder::sources::windowtrack::border_class;
|
||||
///
|
||||
/// assert_eq!(border_class("komoborder-5d1c-uuid"), Some(None));
|
||||
/// assert_eq!(border_class("komoborder-131072"), Some(Some(131072)));
|
||||
/// assert_eq!(border_class("Chrome_WidgetWin_1"), None);
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn border_class(class: &str) -> Option<Option<u32>> {
|
||||
let id = class.strip_prefix("komoborder")?;
|
||||
Some(id.strip_prefix('-').and_then(|id| id.parse().ok()))
|
||||
}
|
||||
|
||||
/// Decides which samples become rows: the first, any that differ from the previous sample, and one
|
||||
/// per [`KEYFRAME_INTERVAL_NS`] otherwise. See the module docs for an example.
|
||||
#[derive(Debug, Default)]
|
||||
@@ -361,6 +413,8 @@ mod tests {
|
||||
visible: true,
|
||||
minimized: false,
|
||||
cloaked: None,
|
||||
border: false,
|
||||
border_of: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,6 +469,25 @@ mod tests {
|
||||
assert!(changed(&mut filter, 6, vec![window(2, 0)]).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn borders_are_told_by_their_class_and_the_old_format_still_reads() {
|
||||
assert_eq!(border_class("komoborder-9f"), Some(None));
|
||||
assert_eq!(border_class("komoborder-42"), Some(Some(42)));
|
||||
assert_eq!(border_class("komoborder"), Some(None));
|
||||
assert_eq!(border_class("notkomoborder-1"), None);
|
||||
let old = r#"{"mach_ns":1,"windows":[{"id":1,"owner":"a","rect":[0,0,1,1],"visible":true,"minimized":false}]}"#;
|
||||
let row: TrackRow = serde_json::from_str(old).unwrap();
|
||||
assert!(!row.windows[0].border && row.windows[0].border_of.is_none());
|
||||
let mut border = window(2, 0);
|
||||
border.border = true;
|
||||
border.border_of = Some(1);
|
||||
let text = serde_json::to_string(&border).unwrap();
|
||||
assert!(
|
||||
text.contains("\"border\":true") && text.contains("\"border_of\":1"),
|
||||
"{text}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_round_trip_and_leave_out_what_is_empty() {
|
||||
let row = TrackRow {
|
||||
|
||||
@@ -125,6 +125,8 @@ impl SessionBuilder {
|
||||
visible: true,
|
||||
minimized: false,
|
||||
cloaked: Some(false),
|
||||
border: false,
|
||||
border_of: None,
|
||||
},
|
||||
)
|
||||
.collect(),
|
||||
|
||||
Reference in new issue
Block a user