A window that scrolled out of view in the Scrolling layout used to be sent
to a corner of the screen and hidden there. It now comes to rest at the
edge of the screen that it left by, with a sliver of it on screen, and
keeps its size and its height up the screen. Bringing it back is then a
matter of moving it, and it never has to be resized.
With animations on the window slides there and stays, where it used to
carry on into the corner. With animations off it is moved there at once,
so the layout behaves the same either way. Where the edge is next to
another display, and the window would be seen on it, it is still hidden
in the corner.
The marker that says a window is out of the way is now also cleared when
a window is put back without animating it. Only sliding a window in
cleared it, which was enough only while nothing set the marker unless
animations were on.
The Scrolling layout is now laid out by komorebi-scrolling instead of by
the layouts crate. A workspace in that layout keeps a ScrollingSpace next
to its containers, makes it match the containers and the focus whenever
the layout is calculated, and takes the rectangles from it. As a result:
- a window that opens gets the width of a column and no other column
changes width, where every column used to be resized to share the
viewport until there were as many as `columns`
- focusing a column that is already in view does not scroll the strip
- a column that has been resized keeps its width as windows come and go
- columns that were never resized follow the `columns` option, so
changing it, or crossing a threshold of layout_options_rules, still
lays them out again
Resizing changes the width of the focused column, by half of the delta
per edge as the other layouts do. A strip has no heights, so resizing a
height does nothing.
Windows that are partly in view keep their size and overhang the edge of
the screen, unless that would show them on another display, where they
are clamped to the work area as before.
What needs a Workspace is in the scrolling module, and what does not is
in komorebi_layouts::scrolling, which the model comes through. What only
the old Scrolling layout needed goes: the percentage override in
update(), laying the strip out again without resize adjustments in
hide(), the resize constraints, and the feedback of the unclamped
layout.
komorebi-layouts now carries the platform-free half of the Scrolling
layout: the model of a strip of columns, re-exported as
komorebi_layouts::scrolling::model, and what a host needs around it,
which is the layout options for the model, the placement of containers
in a work area, resizing a column or a tile, and the hand-over of column
records between workspaces.
The center_focused_column layout option of the Scrolling layout is one
of Never, Always and OnOverflow there, and a boolean is still read as
true for Always and false for Never. The two places here that said true
say Always, and the schema and the options for nix say so.
This is the revision of the feature/moar-scrolling branch of komorebi
that has them. It is pinned by revision until the branch is merged, and
komorebi-themes moves with it so that the repository is fetched once.
komorebi-scrolling has no license field, so deny.toml clarifies it as it
does the other crates of that repository.
The command only set the column count when the workspace had no layout
options at all, or already had scrolling options. A workspace with
options for something else (column_ratios, say) and no scrolling options
matched the second arm and was left unchanged, so the command silently
did nothing.
Move the logic to Workspace::set_scrolling_columns, which creates the
scrolling options when they are missing and keeps every other option,
and test all three cases.
The Scrolling layout works out which column is first in view from the
layout it produced last time. Workspace::update stored that layout after
clamping it to the work area, which pulls every off-screen column onto
the left edge, so the previous view always read as starting at column 0.
Once more windows were open than fit on screen, focusing left shifted the
whole strip by a column on every step instead of leaving it where it was.
Keep the layout as the algorithm produced it and feed that back for
Scrolling, both in Workspace::update and in resize_window. The clamp
becomes a function of its own so that the regression test runs the same
code as update().
An app is free to refuse a size, and many do: a window that will not get
narrower than some width stays that wide however it is asked. The animator is
the first to find out, when it looks at a window after a journey, and until now
it only re-sent the size and moved on, so a layout that places the next column
as if the window had the width it was given places it on top of the window that
did not.
The arrival module is new here. It is where whatever finds out that a window is
wider than it was told to be says so, from any thread and without the lock of
the window manager, for a layout to pick up the next time that it runs.
Say what every verification found to it, which keeps the windows that
turned out wider than they were told to be for the layout to pick up, and
forgets those that have taken their size since, so it is said every time and
whatever the answer. That includes the last attempt, where the window is looked
at again after it was last told to take its size, as nothing verifies it after
that and the attempts are given up on.
This is said from where the frame is read, not carried out of the state machine,
which has no business with anything global.
take_unfinished only knew about a journey that was to go on to somewhere else
afterwards and never got there. A window that slides out of view in the
Scrolling layout rests where it slid to and has nowhere to go afterwards, so a
slide that was cut short went unnoticed, and the window was left partly in view.
Count every journey that ends other than by the window being found where it was
sent: one that was grabbed or taken over, given up on because the app stopped
answering or the window was gone, or that never got to where it was sent in the
verifications that follow. A journey that settles is not cut short, and nobody
has to ask for the news to be kept within bounds.
Describe the duration, style and fps options, per-animation settings, and what
to expect from the animator: windows stay in step with each other, apps that are
slow to resize are sent sizes less often, and a window that is grabbed is let
go of.
Windows that scroll out of view were hidden with an instant jump to a corner of
the screen, and animated back in diagonally across it. With animations on, slide
them out sideways to the edge of the screen they left by, at the same height,
and park them in the corner once they are out of sight; and put a parked window
back at that edge before it slides in, so that it comes from where it left.
Windows that would be seen on a neighbouring display on the way fall back to the
instant hide, and a window that is stopped on its way out is hidden again rather
than left in view.
Without animations nothing changes.
hide, restore and the direct position and size writers wrote to a window while
an animation thread kept writing frames to it. Take the window over first, which
stops its animation and waits for what is already on its way to land, so that it
cannot land on top of what the caller writes next.
A window that is hidden while it is on its way somewhere is now restored to
where it was going, rather than to wherever it happened to be at the time.
The moves and resizes the animator makes are reported back to us like any
others. They used to be avoided by removing and re-adding the AX observers
around every animation, which cost four AX calls a window and still let some
through. Recognise them instead: a notification for any window of an app we are
moving, or have moved in the last 300ms, is an echo and is swallowed. With the
mouse down it is only taken for somebody grabbing the window, and the animation
let go of, if the window's origin is nowhere we put it, so that apps which snap
or clamp their size are not mistaken for a drag.
Once an app has had a window animated, the move and resize notifications that
arrive while the mouse is up are also throttled per window, so that an app that
will not stop reporting cannot fill the event channel and cost the window
manager real events such as focus changes.
Borders no longer ask a window where it is while it is being animated, as the
animator moves them. A drag cancels the animation of the window being dragged,
and what is known about a process is forgotten when it terminates, as a new
process may be given the same id.
Every animated window used to get a thread of its own that slept between frames,
so neighbouring windows moved out of step, a retarget had to wait for the old
thread to notice (a 125ms poll), every frame wrote both the position and the
size, and the app-side animation guard was applied to the window element, where
AXEnhancedUserInterface does not live, instead of the application element.
Move windows with the animator instead, and remove the thread-per-window engine
and the render dispatcher. Stacking operations suspend animations with a guard
instead of swapping the global flag, which was left off for good if the
operation failed, and the animator is shut down before the daemon puts every
window back where it found it.
The configuration is untouched: enabled, duration, style and fps, global or per
animation, are read exactly as before, and nothing is added to it. An fps of 0
no longer panics.
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.