Commit Graph
27 Commits
Author SHA1 Message Date
LGUG2Z 7c1ab9a6cc fix(wm): handle ghost tiles from electron apps hijacking cmd+w
Some Electron apps like Discord hijack CMD+W to send
`AXApplicationHidden` instead of properly closing/destroying the window.

This causes ghost tiles because the window still exists in the
accessibility API with valid geometry even though it is no longer
visible on the screen.

When `AXApplicationHidden` fires for an app with exactly 1 window, we
now force-reap that window by passing an empty `valid_window_ids` list.

This treats single- window hide events as closes, which is the correct
behavior for apps that hijack CMD+W. Apps with multiple windows continue
to use normal orphan reaping.

I'm still not sure if this is too broad; we may need to use an allowlist
approach for this if it causes changes with other apps.
2026-01-12 13:20:41 -08:00
LGUG2Z d91e14bd71 build(just): consolidate schemapub target 2026-01-04 21:11:28 -08:00
LGUG2Z aac1e9ecf2 build(just): start using vararg build/install target variants 2026-01-03 11:39:26 -08:00
LGUG2Z ff8c852e62 docs(schema): ensure every enum variant has a renderable title 2025-12-27 20:07:17 -08:00
LGUG2Z f290c7e037 docs(config): encode defaults of unwrapped options into schema
This commit ensures that the various default values that the different
Option<T> config properties can be unwrapped to are encoded by schemars
so that they can be picked up by docgen and nixgen.
2025-12-26 15:19:33 -08:00
LGUG2Z 4e66b46e87 docs(schema): clean up unused schema opts from windows
This commit removes some Windows-only schema opts from StaticConfig and
updates the justfile to start generating content for the new Starlight
documentation site.
2025-12-26 11:02:47 -08:00
LGUG2Z 23aca28267 build(nix): add generated module opts and validation
This commit adds NixOS module option generation for komorebi and
komorebi-bar configurations, along with a nix and JSONSchema validation
test harness that runs as part of `nix flake check`.

`schemars-nixgen` (same as `schemars-docgen`, not sure if I'm gonna
release this...) generates strongly-typed Nix option definitions from
the generated JSONSchema files, allowing users to write type-checked Nix
configurations that map directly to the config files.

This will eventually be plugged into a nix-darwin module which I have
yet to start writing.
2025-12-24 17:18:41 -08:00
LGUG2Z b922dc3faa refactor(nix): bring shell directly into flake and pin cargo 2025-12-24 08:36:18 -08:00
LGUG2Z af77e2c944 perf(deps): minimize objc2 cargo features to reduce build time
This commit optimizes the objc2 dependency tree by disabling default
features and enabling only the minimal set of features actually used
by the codebase. This reduces compilation time and dependency bloat.

I was meant to do this earlier but during the initial implementation it was
easier to just pull in everything. Now that we are getting ready for a public
release it's time to improve on this.

I ended up:

* Removing unused direct dependencies:
  - objc2-core-services
  - objc2-core-video

* Setting `default-features = false` on all objc2 crates and added only
  the specific features required for the types and methods used

* Updating objc2, objc2-app-kit, objc2-foundation,
  objc2-application-services, objc2-core-foundation, objc2-core-graphics,
  and objc2-quartz-core with minimal feature sets

After all those changes, the following transitive dependencies are no longer
pulled in: objc2-metal, objc2-core-image, objc2-core-data, objc2-cloud-kit,
objc2-core-text, and loads of unused Foundation/AppKit class bindings.

Some before and after numbers:

| Metric                          | Before  | After   | Change   |
|---------------------------------|---------|---------|----------|
| objc2 dep lines (komorebi)      | 84      | 50      | -40.5%   |
| objc2 dep lines (komorebi-bar)  | 91      | 59      | -35.2%   |
| Dependency tree (komorebi)      | 973     | 917     | -5.8%    |
| Dependency tree (komorebi-bar)  | 1181    | 1131    | -4.2%    |
| Clean build time                | 3m 05s  | 2m 21s  | -23.8%   |

The almost 24% reduction in clean build time is a big win!
2025-12-23 19:38:11 -08:00
LGUG2Z 1e71cb7d92 docs(schema): publish versioned schema docs to lgug2z.com 2025-12-23 12:00:13 -08:00
LGUG2Z 82de4dd230 build(nix): clean runtime build inputs 2025-11-30 13:47:08 -08:00
LGUG2Z 2ff76f0881 fix(wm): disable monocle mode if window is closed
This commit ensures that monocle mode will be automatically disabled if
the last window in a monocle container is closed.
2025-11-29 14:41:25 -08:00
LGUG2Z 6b980a0360 fix(border): close nswindow on main thread
This commit addresses a bug that was introduced/made visible in a5cbb4d.

The nixpkgs flake input (tracking nixpkgs-unstable) was updated from
github:NixOS/nixpkgs/f6b44b2401525650256b977063dbcf830f762369 to
github:NixOS/nixpkgs/0d59e0290eefe0f12512043842d7096c4070f30e and as a
result the version of AppKit being linked against jumped from
2022.44.149 to 2487.50.124.

Builds prior to a5cbb4d were building against macOS 13 (Ventura) era
frameworks due to the use of compatability stubs in nixpkgs, whereas the
nixpkgs-unstable update in a5cbb4d now links against the actual running
system's framework versions (in this case, macOS 15).

With github:NixOS/nixpkgs/f6b44b2401525650256b977063dbcf830f762369:

```
❯ otool -L target/debug/komorebi | grep -E 'AppKit|Foundation|CoreFoundation|libSystem'
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1775.118.101)
        /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2022.44.149)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1775.118.101)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)
```

With github:NixOS/nixpkgs/0d59e0290eefe0f12512043842d7096c4070f30e

```
❯ otool -L target/debug/komorebi | grep -E 'AppKit|Foundation|CoreFoundation|libSystem'
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2420.0.0)
        /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 2487.50.124)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 2420.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.100.2)
```

Somewhere between macOS 13 and macOS 15 Apple added stricter
thread-safety assertions in the AppKit framework, which resulted in the
calls to `NSWindow::close()` in border.rs to crash on an assertion
failure ("transaction must be valid")

```
* thread #9, stop reason = EXC_BREAKPOINT (code=1, subcode=0x19e543cc0)
    frame #0: 0x000000019e543cc0 AppKit`-[NSWMWindowCoordinator performTransactionUsingBlock:] + 752
AppKit`-[NSWMWindowCoordinator performTransactionUsingBlock:]:
->  0x19e543cc0 <+752>: brk    #0x1
    0x19e543cc4 <+756>: adrp   x0, 827
    0x19e543cc8 <+760>: add    x0, x0, #0x4ba ; "assertion failure: transaction must be valid"
    0x19e543ccc <+764>: bl     0x19e6eb58c    ; symbol stub for: _os_crash
Target 0: (komorebi) stopped.
(lldb) bt
* thread #9, stop reason = EXC_BREAKPOINT (code=1, subcode=0x19e543cc0)
  * frame #0: 0x000000019e543cc0 AppKit`-[NSWMWindowCoordinator performTransactionUsingBlock:] + 752
    frame #1: 0x000000019e372a00 AppKit`-[NSWindow(NSWMWindowManagement) window:didUpdateWithChangedProperties:] + 104
    frame #2: 0x000000027a366720 WindowManagement`-[_WMWindow performUpdatesUsingBlock:] + 100
    frame #3: 0x000000027a365714 WindowManagement`-[_WMWindow applyTags😷] + 712
    frame #4: 0x000000027a365cf8 WindowManagement`-[_WMWindow setVisible:] + 84
    frame #5: 0x000000019d91b064 AppKit`-[NSWindow _setVisible:] + 268
    frame #6: 0x000000019da16df0 AppKit`-[NSWindow _doWindowWillBecomeHidden] + 88
    frame #7: 0x000000019e3662e0 AppKit`-[NSWindow _reallyDoOrderWindowOutRelativeTo:] + 160
    frame #8: 0x000000019e366794 AppKit`-[NSWindow _reallyDoOrderWindow:] + 80
    frame #9: 0x000000019e3669e4 AppKit`-[NSWindow _doOrderWindow:] + 264
    frame #10: 0x000000019e360c84 AppKit`-[NSWindow _finishClosingWindow] + 444
    frame #11: 0x000000019daa6cc8 AppKit`-[NSWindow _close] + 380
    frame #12: 0x0000000100c3380c komorebi`_$LT$$LP$$RP$$u20$as$u20$objc2..encode..EncodeArguments$GT$::__invoke::h1be54296556f108b(msg_send_fn=(libobjc.A.dylib`objc_msgSend), receiver=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58e38, (null)=<unavailable>) at encode.rs:433:26
    frame #13: 0x0000000100c30f84 komorebi`objc2::runtime::message_receiver::msg_send_primitive::send::h0de1c4d240a2223f(receiver=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58e78, args=<unavailable>) at message_receiver.rs:172:18
    frame #14: 0x0000000100c2e904 komorebi`objc2::runtime::message_receiver::MessageReceiver::send_message::h86c04ca17a2b6faf(self=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58ed0, args=<unavailable>) at message_receiver.rs:432:38
    frame #15: 0x0000000100b9b1bc komorebi`_$LT$MethodFamily$u20$as$u20$objc2..__macro_helpers..msg_send_retained..MsgSend$LT$Receiver$C$Return$GT$$GT$::send_message::h6cb30a52e558d44c(receiver=0x0000000132e09ea0, sel=Sel @ 0x0000000170b58f48, args=<unavailable>) at msg_send_retained.rs:35:28
    frame #16: 0x0000000100ba14b8 komorebi`objc2_app_kit::generated::__NSWindow::NSWindow::close::h34bc4ef6fc286b23(self=0x0000000132e09ea0) at extern_methods.rs:266:14
    frame #17: 0x00000001002b22f0 komorebi`komorebi::border_manager::border::Border::destroy::_$u7b$$u7b$closure$u7d$$u7d$::h61d54fa62ea0b107((null)=AutoreleasePool @ 0x0000000170b58fb8) at border.rs:161:35
```

To fix this, this commit ensures that the call to `NSWindow::close()` is
made on the main thread using `DispatchQueue::main().exec_sync()`.
2025-11-29 14:09:26 -08:00
LGUG2Z db8cf858ff build(nix): pull git rev info from flake inputs
This commit adds a new workspace crate, version, which is consumed by
komorebi and komorebic.

If either of those binaries are being built by
the Nix Flake, the git rev info will be pulled from inputs.self.rev
instead of querying the git repo, because the git files are not passed
to the derivation.

The build.rs for the version crate decides if the build is happening by
querying the shadow-rs build output for BRANCH, which will always be
empty when a "nix build" is running.

Cargo builds will use the standard git information retrieval mechanisms
in shadow-rs.

The information in both cases is exposed as version::LONG_VERSION, and
passed to clap as the string to return when either binary is called with
the --version flag.
2025-11-06 16:57:17 -08:00
LGUG2Z 9dbae50909 feat(wm): add a splash screen for mdm devices
A little nudge for people to do the right thing, 1990s vibes.
2025-10-28 18:25:05 -07:00
LGUG2Z 7bb0aaac48 feat(cli): add docgen cmd and jsonschema just target
This commit adds a docgen command to generate markdown documentation
files of all of the CLI commands, and a justfile target to generate
JSONSchema files.
2025-09-26 12:49:23 -07:00
LGUG2Z fa6ce669f7 fix(wm): use absolute monitor sizes and fix deadlock
This commit switches to using absolute intead of relative monitor sizes,
I don't fully understand by the NS APIs and the CG APIs return totally
different coordinate systems.

There was also a deadlock in the monitor reconciliator which I think I
figured out; it's a little ugly both in code and in execution but the
deadlocks and pkill -9s can be put away from now.

Cross-monitor moves aren't working which I'll look into next.
2025-09-26 09:53:37 -07:00
LGUG2Z 8a17e0ad00 feat(wm): add socket subscriptions
This commit adds in the ability for users to subscribe to notifications
via a Unix domain socket. Code was mostly just migrated from komorebi.
Tested with "nc -vklU $(komorebic datadir)/test.sock" to create the
socket and listen and then "komorebic subscribe-socket test.sock" to
subscribe for notifications.
2025-09-24 16:30:44 -07:00
LGUG2Z 84d27f83e0 fix(wm): make hidden windows take up less space 2025-09-22 14:26:21 -07:00
LGUG2Z f6997577f1 fix(wm): respect workspace window rules
This commit adds window ID tracking like we do in komorebi for Windows
and fixes a bunch of bugs that were happening when a window on another
workspace was focused either via the Dock or cmd+tab, and also a bug in
workspace rules where on launch, a window would not respect workspace
rules due to another workaround that had been added to make Apple apps
work nicely.
2025-09-22 13:31:45 -07:00
LGUG2Z c84db9a894 feat(wm): impl state, global-state and visible-windows
This commit implements the State, GlobalState and VisibleWindows
SocketMessage variants. These are the first of the SocketMessage
variants send by komorebic which receive a reply which is printed out to
the console.

I think the next thing to do will probably be to get the extended
display info so that the MonitorInformation variant can be handled too.
2025-09-21 21:07:52 -07:00
LGUG2Z a4bc40aa5e feat(wm): add notification center listener
This commit adds a listener for the NotificationCenter of the
SharedWorkspace, which allows us to be notified of acts like new app
creation, app termination (different from app window destruction),
application hides and application unhides, among many others.

There are a lot of the AppKit notifications which can be registered with
observers on the notification center; for now I have just modeled the
AppKitWorkspaceNotification enum which seems to hold the most
interesting notifications for our use case.

NSWorkspaceDidLaunchApplicationNotification and
NSWorkspaceDidTerminateApplicationNotification are now hooked in to the
Show and Destroy WindowManagerEvents, but I still need to think about
how to hook in the events around hiding and unhiding as these are
temporary/reversible actions which operate across multiple application
windows, unlike minimize/restore which only operate on one application
window at a time.
2025-09-21 09:22:54 -07:00
LGUG2Z b7ce8c03b5 refactor(rust): standardize on ok_or_eyre and bail!
This commit standardizes the codebase to disallow usage of the raw eyre!
macro for creating errors, instead using ok_or_eyre() when constructing
ad-hoc errors from Result and Option types, and otherwise using the
bail! macro in response to failed boolean conditions.
2025-09-20 10:24:42 -07:00
LGUG2Z 71adb1c0e0 feat(wm): implement basic workspace layers
This commit implements some of the basic plumbing needed to handle
SocketMessage::ToggleWorkspaceLayer and SocketMessage::ToggleFloat.

I've commented out a bunch of the raise/lower functions for now because
I haven't had time to learn about how changing z-ordering on macOS works
yet.

Even so, this is fairly functional, and it's possible to move floating
windows across workspaces, toggle the workspace layer, move floating
windows by the resize delta, and change focus between floating windows.

I ended up moving the window restore positions to a global map because
storing/updating this kind of state on the Window properly will be a
pain because hide/restore now require mut self refs and that leads to
needing to clone sometimes.
2025-09-19 08:51:30 -07:00
LGUG2Z 4f6267b56e feat(wm): add basic window manager event handling
This commit adds a WindowManagerEvent enum and a channel to send and
receive variants of it on.

The skeleton of process_event has been migrated from komorebi and a few
basic implementations of handlers for core events like FocusChange,
Show, Destroy, Minimize and Restore have been added.

Due to the way the window observers work, in komorebi for Mac we'll need
to keep track of minimized Windows so that we don't drop their observers
(otherwise we won't receive a notification when they are restored).

Most of the code added in this commit around modifying state in response
to these events has been migrated from komorebi.
2025-09-18 11:12:27 -07:00
LGUG2Z b6d19e6a12 feat(wm): migrate workspace and layout code
This commit migrates big chunks of code from komorebi for Windows which
deal with state related to the Workspace struct, Layouts and the
Arrangement trait.

Layout remains an enum, but only the Layout::Default variant with
DefaultLayout has been migrated because there are no plans to support
EOL features in komorebi for Mac (custom layouts).

The code for updating the layout in main.rs has been moved to
Workspace.update, which is now called from main.rs instead.

As part of this initial migration of code, this project has been
restructured a little to match the layout of komorebi for Windows to
minimize my own confusion.
2025-09-17 13:31:39 -07:00
LGUG2Z 2b99a68ed8 feat(wm): initial commit 2025-09-16 16:53:11 -07:00