Run the state machine on one frame thread that steps every animated window on
the same clock, and hand the writes to a lane per app, which make them side by
side. The frame thread never talks to an app, and a frame is only started once
the last has been applied to every moving window, so that neighbouring windows
stay on the same frame and the gaps between them do not open and close. An app
that takes longer than a frame is not waited for.
Also expose the pieces the window manager needs around it: animation::motion_for
to read the configured duration and style for a kind of animation, and
animation::suspend to skip animations for as long as an operation runs, which
unlike turning the global setting off and on again puts everything back when the
operation fails part of the way through.
Nothing uses it yet.
Borders follow a window through their own AX observer, which asks the window
where it is over AX on the main thread for every notification, so a border lags
a window that is being moved a frame at a time. Add a way to hand a border the
frame a window has just been moved to instead, batched onto the main thread
once per turn with only the latest frame of each window applied.
The border state is held by the border thread while it creates borders, which
it does by waiting for the main thread, so it is only ever tried, never waited
for, from there; frames that find it busy are put back and tried again.
An app that moves its own windows, or is moved faster than it can report, can
send a notification for every frame, and the window manager's event channel is
small. throttle lets one through per window per interval. stats keeps just
enough of how an animation burst went to answer why it felt slow from the log:
how regular the frames were, and how long the apps took to apply them.
Keep the bookkeeping of an animation free of threads, clocks and macOS APIs, so
that it can be tested with a fake clock. step holds the maths, and tracks knows
which windows are in flight, where each is, where it is going, and what has to
be written to it next, in whole-frame steps that are handed back as commits for
a runtime to carry out:
- retargeting a window overwrites its target and carries on from where it is
- only the dimension that changed is written, and an app that is slow to apply
a size is sent them less often, so that it keeps moving in between
- where a window was last put is remembered, so that a window can be animated
without asking it where it is
- a finished window is verified, and re-sent if the app ignored the move
- work that is never reported on is given up on after a few seconds
- the notifications our own writes cause are recognised as echoes, by window
and by process, unless the mouse is down and the window's origin is nowhere
we put it, in which case somebody has grabbed it
AXEnhancedUserInterface makes an app animate every move and resize it is asked
to make over AX. It belongs to the application element, not to a window, and it
is shared by all of an application's windows, so turning it off has to be
reference counted per process, with the last window to finish putting it back.
Almost no app has it on, so an app that has been seen not to is left alone for
a while without being asked again.
Also add a messaging timeout helper, so that an app that has hung cannot hold a
caller for several seconds, and expose the application's own element.
notify_on_error needed a whole Window to decide whether a failed write meant
that the window was gone, but only used its id and its element. The tabbed
application check was also subsumed by the validity check that follows it: a
window whose element still answers is never reaped. Add notify_if_gone, which
takes just the id and the element, for writers that do not have a Window,
and have notify_on_error call it.
Workspace::update asked every window where it was, which is a round trip to
the app that owns it, before deciding what to do with it. The answer only
matters for a window that the layout would put entirely out of view, so ask
only then.
Bring the generated files back in line with the code on master.
- schema.json: add monocle_focus_behaviour and the MonocleFocusBehaviour
definition. schema.asc.json and schema.bar.json were already current.
- nix/komorebi-options.nix: add the monocle_focus_behaviour option.
nix/komorebi-bar-options.nix was already current.
- docs/cli: add the pages for layout-ratios, monocle-focus-behaviour,
permissions and toggle-monocle-focus-behaviour. Update 19 pages for
the --bar flag of enable-autostart, the per-value help of enum
arguments and reworded help text. Re-wrap 4 pages whose text did not
change.
How the files were made:
- schemars-nixgen writes the properties of an object in a different
order on every run, so the files are not regenerated whole. Only the
new option is added; the rest of a full run was checked to be the same
lines in another order.
- docgen on master writes a bare fence with no heading and "Usage: name",
where the pages in docs/cli have a "# name" heading and "Usage:
komorebic name". The pages keep the format they have.
- Pages are wrapped at 100 columns, the width docgen uses when it does
not write to a terminal, instead of the width of the terminal the old
pages were made in.
komorebi focuses one window of an application next to another of its
windows, and the application can be slow to say that window is the one
focused, or not say it at all. The border was decided on what the window
server reported, still the other window, so the focused window had none.
Count the window in the focused container as the one with the focus when
the window the window server reports is another window of the same
application that komorebi manages. The decision is a function with tests,
and the border manager traces what it decided for each container.
An application that comes to the front names its main window, which is
not necessarily the one komorebi focused. When it is another of the
application's windows, komorebi took it as a request to go there:
- parked on another workspace, the workspace reconciliator switched to
that workspace, so a focus command between windows of one application
changed workspace;
- beside the focused window on the workspace that is showing, its
container took the focus back, so the window komorebi had just focused
lost it.
Do neither when the notification is the application coming to the front
and one of its windows is the focused one here. Choosing a window of the
application is said with AXMainWindowChanged and is still followed. The
decisions are functions with tests.
Closing a laptop lid with an external display attached swaps one display
for another, so the monitor count is unchanged and the reconciliator
logged "reconciliation not required" while komorebi kept laying windows
out on the old display's work area. Compare the serial numbers as well as
the count and hand the unplugged monitor's workspaces to the display that
took its place.
The workspaces that are not showing kept the work area of the old display
too, so they were put away on a display that was gone and their windows
stayed in view. Refresh the work area of every workspace before putting
them away, and let a window that cannot be hidden not leave the ones
after it in view.
Resize notifications matched monitors by display id, which changes when a
display is reconnected, so they never updated anything and then re-laid
out the focused workspace once per device. Match by serial number, and
only re-lay out when a known monitor changed.
When an application on a hidden workspace came to the front, its focus
was not followed to its workspace, and when it was, the window that came
to the front was not the one that ended up focused.
Follow the notification to its window when the application has no main
window to ask for, say when that was needed, and focus the container of
that window before the reconciliator loads the workspace, instead of
the one the workspace last had focused. The stale focus check then
agrees with where focus went.
A notification that an application came to the front is not followed
while another application is in front. That is right when komorebi has
since moved on to another, and it is also all there is to see when the
window server refused to bring the application to the front at all, in
which case focus moves in komorebi and nowhere else. At debug level it
was left out of the log by default, so the only trace of that refusal
was in the OS log. Make it a warning.
Focusing a window activated its application with NSRunningApplication,
which from a background process reaches the window server as a request
stamped with the time komorebi started. Once the user has typed or
clicked since, the window server turns it away as expired ("Rejecting
expired request") and the application that was in front stays there:
focus moves in komorebi, the border, which only marks the window that
has the keyboard, stays unfocused, and the keys keep going to the
terminal that `komorebic focus` was run from.
Ask the window server directly first, with the request marked as the
user's, which is what clicking a window does. The two private symbols
it takes are looked up when first wanted and not linked, so that macOS
taking one away leaves komorebi starting and focusing as it did, with
one warning. A window server that refuses three times in a row is not
asked again, and a process without a serial number is left to the
usual way without counting against it.
Switching workspace hides the windows of the others and restores the
windows of the one that is wanted, one window at a time, each through
the accessibility API and each as slow as the app it belongs to. The
handler took 260 to 430 ms in a recording, and frames taken in the
middle of it show both workspaces on screen together: with Zed and Zen
gone, two WezTerm windows from the old workspace still up and Beeper
and Discord from the new one not there yet.
Workspace::update already batches its window moves with SLSDisableUpdate
and SLSReenableUpdate so that they appear together. Hiding and restoring
did not. BatchedUpdates holds the screen back until it is dropped, which
an early return does too, so an error cannot leave it frozen, and
load_focused_workspace keeps one for the hiding and the restoring. The
wallpaper, which can generate a theme, is put up after it is dropped,
which is why Workspace::restore is split into the windows and the
wallpaper. restore does what it did.
The screen does not change at all for as long as it is held, which is
now the length of the switch. How the private SkyLight calls behave
when it is held for that long, and whether it is long enough to notice,
was not tried on a screen.
komorebi brings an app to the front with activateWithOptions and then
hears about it from NSWorkspace and the accessibility API some time
later, 0.8 to 1.7 s in a recording, by which time it has often brought
another app to the front. The FocusChange handler took every such
notification at its word, which had two effects:
- focus moved back to the app that had had it, so Left, Left landed on
the window in between rather than the one two along
- the app of a window on a workspace that is not showing made the
workspace reconciliator switch to that workspace, which undid a
workspace change that had been asked for a moment earlier
The handler now asks which app is in front and does not follow a
notification about any other. The last notification that is followed
is always about the app that really is in front, so the state ends up
where the system is. Notifications about an app that is not in front
still go through the rest of the handler, and nothing is ignored when
the accessibility API will not say what is in front.
Found in a recording of the installed build at db1c18b. That the
notifications are late and that the OS front process had moved on was
read off the OS trace; the change itself is tested only for the
decision, and was not tried on a screen.
Dragging a tile's edge was unreliable: long drags were dropped, the
divider next to a different window drifted by a few points, and in
recordings made with komorebi-recorder a drag to the left shrank the tile
instead of growing it. This fixes the causes that were found there.
Resize bounds: bump komorebi-layouts and komorebi-themes to
LGUG2Z/komorebi@f08aa55, where DefaultLayout::resize only accumulates and
no longer refuses any adjustment larger than half of the container's own
size. resize_window now grants the largest amount that keeps every tile
at least a tenth of the work area (or as large as it already is), found
by bisection, instead of all or nothing. Keyboard resizing goes through
the same path. RUSTSEC-2024-0449 is ignored in deny.toml, as upstream
does in the same bump.
The dragged container: ResizeStart records the rect of the dragged window
once, since AXWindowResized fires again all through a drag, and ResizeEnd
hands it to the new WindowManager::resize_by_drag along with the rect the
window ended in. That resizes the container of the dragged window instead
of the focused one, for each edge that moved, instead of guessing the
edges from the difference to latest_layout (which made apps that snap to
a grid of cells resize edges that nobody touched).
Where the drag began: AXWindowResized is first reported after the edge
has moved, and handlers run one at a time, so the rect recorded as the
start can already be 22 points into the drag, or be the rect the drag
ended in. An edge that ended up more than 32 points from its tile is
measured from its tile edge; every other edge from the recorded start.
The reaper: it re-tiled the focused workspace on every mouse-up and
key-up to find windows that had gone away. That ran as soon as the button
went up, ahead of the ResizeEnd queued behind slower handlers, so the
window was back on its tile when ResizeEnd read where it had been dropped
and the drag was measured backwards. It now only looks for windows that
no longer exist and reaps them, without moving any window.
The tests reproduce each of these, including the numbers from the
recordings: a first step of 22 points, a drag already over when it was
first seen, and a mouse-up that must leave the layout alone.
LGUG2Z/komorebi@5f629e1 made directional focus cycle the monocle
container in the underlying ring. Useful on a single monitor, but
undesired when focusing across monitors — the focus stays trapped on the
monocle workspace instead of crossing the boundary.
This commit adds a new top-level monocle_focus_behaviour option with two
variants, Cycle (the post-5f629e1f behaviour) and NoOp (the pre-5f629e1f
behaviour, now the default), along with a ToggleMonocleFocusBehaviour
socket message and corresponding komorebic subcommands to flip between
them at runtime.
This commit fixes a bug where, when toggling on monocle mode, the cursor
would go to the configured hiding corner.
Thanks to ziggee on Discord for pointing this out because I hadn't
noticed it despite using monocle mode all the time!
This was debugged by Lando Calrissian on Discord who submitted this text
patch. The rest of this commit message is from Lando's investigation
summary shared on Discord:
The left panel in komorebi-bar uses `Align2::LEFT_CENTER` anchor, which
vertically centers the panel content within the bar. When switching
between workspaces with windows (icons) and empty workspaces (text
labels only), the content height differed by ~1-2px, causing the
vertical center point to shift - resulting in visible "bobbing" of the
workspace indicators.
The height inconsistency occurred because:
1. `show_icons()` wrapped content in a Frame with inner_margin
2. `show_fallback_icon()` had NO Frame wrapper
3. `show_label()` had NO Frame wrapper and used default text height
Fix:
1. Wrap `show_fallback_icon()` in the same Frame with inner_margin as
show_icons
2. Wrap `show_label()` in the same Frame with inner_margin as show_icons
3. Add `ui.set_min_height(self.icon_size.y)` to show_label to ensure the
label has the same minimum height as icons
4. Change show_label from static to instance method (&self) to access
icon_size
This ensures all three rendering functions produce consistent content
height, preventing the LEFT_CENTER anchor from shifting when workspace
content changes.
This was debugged by Lando Calrissian on Discord who submitted this text
patch. The rest of this commit message is from Lando's investigation
summary shared on Discord:
Every frame, the update() method checks if egui's window rect matches
the stored size_rect. The comparison code multiplied egui's outer_rect
(which is in logical pixels) by scale_factor, producing physical pixel
values (e.g., 3584x40 on a 2x Retina display). But size_rect stores
logical pixel values (1792x20). These can never match on a HiDPI
display, so every frame:
1. `size_rect != current_rect` evaluates to `true`
2. `position_bar()` is called, sending `ViewportCommand::OuterPosition`
and `ViewportCommand::InnerSize`
3. Each `send_viewport_cmd` internally calls `request_repaint()` in egui
4. egui schedules another frame → go to step 1
Result: 120fps continuous rendering, consuming ~12% CPU.
Debugging Method:
Instrumented the code with frame counters, FPS tracking, and repaint
cause logging. Systematically disabled components (repaint thread,
komorebi notifications, widget rendering) to isolate the cause. Traced
egui's repaint causes to context.rs:3853 (send_viewport_cmd_to), then
found the size_rect mismatch firing 1112 times in 10 seconds.
Fix:
Removed the erroneous scale_factor multiplication from the rect
comparison, since outer_rect already reports in logical pixels — the
same coordinate space as size_rect.
Result:
┌────────────┬───────────┬───────────────────┐
│ Metric │ Before │ After │
├────────────┼───────────┼───────────────────┤
│ CPU (idle) │ 12-13% │ 0.0-0.1% │
├────────────┼───────────┼───────────────────┤
│ Frames/sec │ 120 │ ~1 (timer-driven) │
├────────────┼───────────┼───────────────────┤
│ CPU spikes │ Up to 20% │ None observed │
└────────────┴───────────┴───────────────────┘
This commit is largely lift and shift of LGUG2Z/komorebi@c165172:
The implementation adds a new layout-ratio CLI command to komorebi that
allows users to dynamically set column and row ratios for layouts at
runtime via komorebic layout-ratio --columns 0.3 0.4 --rows 0.5.
A public validate_ratios function was added to komorebi-layouts that
clamps ratio values between 0.1 and 0.9, truncates when the cumulative
sum would reach or exceed 1.0, and limits to a maximum of 5 ratios. This
function is shared between config file deserialization and the new CLI
command, ensuring consistent validation behavior.
The SocketMessage enum in komorebi/src/core/mod.rs has a new
LayoutRatios variant. The handler in process_command.rs uses the shared
validate_ratios function to process the ratios before applying them to
the focused workspace's layout options.
When the CLI command is called without any arguments, it prints a
helpful message instead of returning an error.
This commit adds parity with the layout_options and ratio support added
to LGUG2Z/komorebi@22e8a79833 by @CtByte,
which is largely integrated into komorebi for Mac through the importing
of the new komorebi-layouts crate.
This commit migrates to the new komorebi-layouts crate exposed in the
LGUG2Z/komorebi repository, significantly reducing duplication and
change maintenance between the two komorebi implementations.
When Finder is configured as a tabbed application, opening multiple
separate Finder windows (not tabs within the same window) prevented
focusing between those windows using komorebic focus commands.
The tab detection logic uses geometry comparison (tab_rect == main_rect)
to determine if a window event represents a tab change. This fails when
separate windows from the same application have identical geometry after
tiling, causing them to be incorrectly treated as tabs within a single
window.
This commit adds window ID verification as an additional requirement for
tab detection. For Show events, both geometry AND window IDs must match
for the event to be classified as a tab (preventing new container
creation). For FocusChange events, we verify the stored element's window
ID matches the container's stored ID to confirm legitimate tab switches
within the same window.
The geometry check is preserved to maintain existing tab detection, but
now requires window ID confirmation to prevent false positives when
separate windows happen to share identical positions and dimensions.
Additionally, this commit fixes the Window::focus() function for tabbed
applications to prefer using the stored element when valid, only falling
back to main_window() when the element is invalid (tab was closed). This
allows focusing specific windows even for tabbed applications instead of
always focusing the main/frontmost window.
This commit removes the hardcoded entries in TABBED_APPLICATIONS for
Finder and Ghostty, and instead leaves this for users to source either
through their own configs using the "tabbed_applications" config option
or via an ASC file.
There is a slight discrepancy in the two schemas as the personal config
file will accept an Exe string identifying the app, whereas the ASC goes
with a full MatchingRule to keep the ASC consistent.
However, for both tabbed and titleless application options as exposed on
the ASC schema, when read in komorebi it will only accept
MatchingRule::Simple with an Exe identifier.
Resize adjustments can cause container layouts to overflow beyond the
monitor's work area boundaries, bleeding into adjacent monitors.
This happens because the resize adjustment system modifies container
dimensions without validating that the final calculated positions stay
within the monitor's bounds.
On multi-monitor setups (e.g. ultrawide + MacBook display), a large
resize adjustment on one container can push adjacent containers past the
monitor edge, making them visible on the neighboring display.
This commit adds boundary clamping after layout calculation but before
padding is applied. If a layout's calculated position exceeds the work
area bounds (horizontally or vertically), we clamp it to stay within the
monitor's usable space.
Additionally, a unit test validates that layouts with aggressive resize
adjustments (matching the reported issue) are properly clamped to
prevent overflow.