mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-20 15:41:38 +01:00
chore(repo): combine candidate 7 with the pointer-picks-monitor change, the bar wgpu fallback and the macOS deep dedup (candidate 8, before kfw's Windows deep dedup)
Candidate 8 (draft): wip-cand7 plus wip-u-deep (which contains wip-u-ptr: shared focus_workspace_number(s), KDE and macOS get the pointer-picks-monitor preamble, the const removed, and the thin-events design note), wip-u-bar4 (eframe wgpu fallback for the Windows bar, scenario rules) and wip-u-mac-deep (ContainerExt removed, nine shared window_manager functions identical on KDE and macOS, five macOS router arms as named methods). Conflicts, if any, are resolved here.
This commit is contained in:
commit
7a69f692ba
23 files changed
+931
-725
No files matched your search
Generated
+8
@@ -1728,6 +1728,7 @@ dependencies = [
|
||||
"objc2-foundation 0.2.2",
|
||||
"parking_lot 0.12.5",
|
||||
"percent-encoding",
|
||||
"pollster",
|
||||
"profiling",
|
||||
"raw-window-handle",
|
||||
"static_assertions",
|
||||
@@ -1735,6 +1736,7 @@ dependencies = [
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"web-time",
|
||||
"wgpu",
|
||||
"windows-sys 0.61.2",
|
||||
"winit",
|
||||
]
|
||||
@@ -5771,6 +5773,12 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pollster"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.15.0"
|
||||
|
||||
@@ -22,12 +22,6 @@ pub trait CommandHost {
|
||||
/// The platform whose monitors the host has.
|
||||
type P: MonitorPlatform;
|
||||
|
||||
/// Whether the commands that act on the focused monitor first focus the monitor the pointer is
|
||||
/// on when the workspace shown there is empty, for `cycle_focus_empty_workspace`,
|
||||
/// `close_workspace` and `focus_last_workspace` (the other commands always do). Windows does it
|
||||
/// for all of them; KDE and macOS do not.
|
||||
const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = false;
|
||||
|
||||
/// The monitors.
|
||||
fn monitors(&self) -> &VecDeque<Monitor<Self::P>>;
|
||||
|
||||
@@ -49,6 +43,10 @@ pub trait CommandHost {
|
||||
/// Shows workspace `idx` on the focused monitor and focuses it.
|
||||
fn focus_workspace(&mut self, idx: usize) -> eyre::Result<()>;
|
||||
|
||||
/// Shows workspace `workspace_idx` on the monitor at `monitor_idx` (creating it if it is not
|
||||
/// there) without focusing that monitor.
|
||||
fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()>;
|
||||
|
||||
/// Moves the focused container to workspace `idx` of the focused monitor.
|
||||
fn move_container_to_workspace(
|
||||
&mut self,
|
||||
@@ -100,9 +98,7 @@ pub fn cycle_focus_empty_workspace<H: CommandHost>(
|
||||
host: &mut H,
|
||||
direction: CycleDirection,
|
||||
) -> eyre::Result<()> {
|
||||
if H::POINTER_PICKS_THE_MONITOR_FOR_ALL {
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
}
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
|
||||
let focused_monitor = host.focused_monitor().ok_or_eyre("there is no monitor")?;
|
||||
|
||||
@@ -138,9 +134,7 @@ pub fn cycle_focus_empty_workspace<H: CommandHost>(
|
||||
/// Removes the focused workspace when it is empty, unnamed and not the monitor's only one, and
|
||||
/// focuses the one before it
|
||||
pub fn close_workspace<H: CommandHost>(host: &mut H) -> eyre::Result<()> {
|
||||
if H::POINTER_PICKS_THE_MONITOR_FOR_ALL {
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
}
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
|
||||
let mut can_close = false;
|
||||
|
||||
@@ -173,9 +167,7 @@ pub fn close_workspace<H: CommandHost>(host: &mut H) -> eyre::Result<()> {
|
||||
|
||||
/// Focuses the workspace that was focused before this one
|
||||
pub fn focus_last_workspace<H: CommandHost>(host: &mut H) -> eyre::Result<()> {
|
||||
if H::POINTER_PICKS_THE_MONITOR_FOR_ALL {
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
}
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
|
||||
let idx = host
|
||||
.focused_monitor()
|
||||
@@ -367,3 +359,37 @@ pub fn set_container_locked<H: ContainerCommandHost>(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Shows workspace `workspace_idx` on the focused monitor, unless it is the one in front; the
|
||||
/// monitor the pointer is on is focused first when its workspace is empty
|
||||
pub fn focus_workspace_number<H: MonitorCommandHost>(
|
||||
host: &mut H,
|
||||
workspace_idx: usize,
|
||||
) -> eyre::Result<()> {
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
|
||||
if host.focused_workspace_idx().unwrap_or_default() != workspace_idx {
|
||||
host.focus_workspace(workspace_idx)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Shows workspace `workspace_idx` on every monitor, the focused one last; the monitor the pointer
|
||||
/// is on is focused first when its workspace is empty
|
||||
pub fn focus_workspace_numbers<H: CommandHost>(
|
||||
host: &mut H,
|
||||
workspace_idx: usize,
|
||||
) -> eyre::Result<()> {
|
||||
focus_the_monitor_under_the_pointer(host)?;
|
||||
|
||||
let focused_monitor_idx = host.focused_monitor_idx();
|
||||
|
||||
for idx in 0..host.monitors().len() {
|
||||
if idx != focused_monitor_idx {
|
||||
host.show_workspace_on(idx, workspace_idx)?;
|
||||
}
|
||||
}
|
||||
|
||||
host.focus_workspace(workspace_idx)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -473,6 +473,18 @@ pub fn resolve_threshold_match(
|
||||
}
|
||||
|
||||
impl<P: WorkspacePlatform> Workspace<P> {
|
||||
/// Where the windows of this workspace are hidden ([`WorkspacePlatform::hide_spot`]), for the
|
||||
/// calls that hide or stack a window
|
||||
pub fn hide_spot(&self) -> PlatformHideSpot<P> {
|
||||
P::hide_spot(self)
|
||||
}
|
||||
|
||||
/// Where the containers of this workspace are hidden when the whole workspace is
|
||||
/// ([`WorkspacePlatform::hide_spot_on_display`])
|
||||
pub fn hide_spot_on_display(&self) -> PlatformHideSpot<P> {
|
||||
P::hide_spot_on_display(self)
|
||||
}
|
||||
|
||||
/// The containers of the workspace.
|
||||
pub const fn containers(&self) -> &std::collections::VecDeque<Container<P::Window>> {
|
||||
self.containers.elements()
|
||||
|
||||
@@ -98,6 +98,12 @@ impl CommandHost for Host {
|
||||
self.monitors[self.focused].focus_workspace(idx)
|
||||
}
|
||||
|
||||
fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()> {
|
||||
self.calls
|
||||
.push(format!("show_workspace_on {monitor_idx} {workspace_idx}"));
|
||||
self.monitors[monitor_idx].focus_workspace(workspace_idx)
|
||||
}
|
||||
|
||||
fn move_container_to_workspace(
|
||||
&mut self,
|
||||
idx: usize,
|
||||
@@ -227,69 +233,6 @@ fn move_to_last_workspace_moves_the_container_and_remembers_where_it_came_from()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_windows_lets_the_pointer_pick_the_monitor_for_the_empty_and_close_commands() {
|
||||
// the platform switch of CommandHost::POINTER_PICKS_THE_MONITOR_FOR_ALL (default false: KDE and
|
||||
// macOS); a host that says true gets the preamble for close and cycle-empty too
|
||||
struct WindowsLike(Host);
|
||||
|
||||
impl CommandHost for WindowsLike {
|
||||
type P = StubPlatform;
|
||||
const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = true;
|
||||
|
||||
fn monitors(&self) -> &VecDeque<Monitor<StubPlatform>> {
|
||||
self.0.monitors()
|
||||
}
|
||||
fn focused_monitor(&self) -> Option<&Monitor<StubPlatform>> {
|
||||
self.0.focused_monitor()
|
||||
}
|
||||
fn focused_monitor_mut(&mut self) -> Option<&mut Monitor<StubPlatform>> {
|
||||
self.0.focused_monitor_mut()
|
||||
}
|
||||
fn focused_monitor_idx(&self) -> usize {
|
||||
self.0.focused_monitor_idx()
|
||||
}
|
||||
fn monitor_idx_from_current_pos(&mut self) -> Option<usize> {
|
||||
self.0.monitor_idx_from_current_pos()
|
||||
}
|
||||
fn focus_monitor(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
self.0.focus_monitor(idx)
|
||||
}
|
||||
fn focus_workspace(&mut self, idx: usize) -> eyre::Result<()> {
|
||||
self.0.focus_workspace(idx)
|
||||
}
|
||||
fn move_container_to_workspace(
|
||||
&mut self,
|
||||
idx: usize,
|
||||
follow: bool,
|
||||
direction: Option<OperationDirection>,
|
||||
) -> eyre::Result<()> {
|
||||
self.0.move_container_to_workspace(idx, follow, direction)
|
||||
}
|
||||
}
|
||||
|
||||
let mut other = Host::new(2);
|
||||
other.monitors.push_back(monitor(2));
|
||||
other.pointer_on = Some(1);
|
||||
komorebi_core::close_workspace(&mut other).unwrap();
|
||||
assert!(
|
||||
!other
|
||||
.calls
|
||||
.iter()
|
||||
.any(|call| call.starts_with("focus_monitor")),
|
||||
"KDE and macOS do not look at the pointer here"
|
||||
);
|
||||
|
||||
let mut host = WindowsLike({
|
||||
let mut host = Host::new(2);
|
||||
host.monitors.push_back(monitor(2));
|
||||
host.pointer_on = Some(1);
|
||||
host
|
||||
});
|
||||
komorebi_core::close_workspace(&mut host).unwrap();
|
||||
assert_eq!(host.0.calls[0], "focus_monitor 1");
|
||||
}
|
||||
|
||||
impl komorebi_core::MonitorCommandHost for Host {
|
||||
fn mouse_follows_focus(&self) -> bool {
|
||||
true
|
||||
@@ -441,3 +384,56 @@ fn locking_a_container_that_is_not_there_is_ignored_but_a_missing_monitor_or_wor
|
||||
assert!(komorebi_core::set_container_locked(&mut host, 3, 0, 0, true).is_err());
|
||||
assert!(komorebi_core::set_container_locked(&mut host, 0, 9, 0, true).is_err());
|
||||
}
|
||||
|
||||
fn pointer_on_the_second_monitor() -> Host {
|
||||
let mut host = two_monitors();
|
||||
host.pointer_on = Some(1);
|
||||
host
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pointer_picks_the_monitor_for_the_empty_close_last_cycle_and_number_commands_on_all_platforms() {
|
||||
// commands.py: close-workspace, cycle-empty-workspace, focus-last-workspace, focus-workspace,
|
||||
// focus-workspaces; the monitor under the pointer is focused first when its workspace is empty
|
||||
for command in 0..5 {
|
||||
let mut host = pointer_on_the_second_monitor();
|
||||
match command {
|
||||
0 => komorebi_core::close_workspace(&mut host).unwrap(),
|
||||
1 => komorebi_core::focus_last_workspace(&mut host).unwrap(),
|
||||
2 => komorebi_core::cycle_focus_empty_workspace(&mut host, CycleDirection::Next).unwrap(),
|
||||
3 => komorebi_core::focus_workspace_number(&mut host, 1).unwrap(),
|
||||
_ => komorebi_core::focus_workspace_numbers(&mut host, 1).unwrap(),
|
||||
}
|
||||
assert_eq!(host.calls[0], "focus_monitor 1", "command {command}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_workspace_number_only_switches_when_it_is_not_in_front() {
|
||||
// commands.py: "focus-workspace 1", "focus-workspace 0"
|
||||
let mut host = Host::new(3);
|
||||
|
||||
komorebi_core::focus_workspace_number(&mut host, 0).unwrap();
|
||||
assert!(host.calls.is_empty());
|
||||
|
||||
komorebi_core::focus_workspace_number(&mut host, 2).unwrap();
|
||||
assert_eq!(host.calls, ["focus_workspace 2"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_workspaces_shows_the_workspace_on_every_other_monitor_then_on_the_focused_one() {
|
||||
// commands.py: "focus-workspaces 1", "focus-workspaces 0"
|
||||
let mut host = two_monitors();
|
||||
host.monitors.push_back(monitor(3));
|
||||
|
||||
komorebi_core::focus_workspace_numbers(&mut host, 2).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
host.calls,
|
||||
[
|
||||
"show_workspace_on 1 2",
|
||||
"show_workspace_on 2 2",
|
||||
"focus_workspace 2"
|
||||
]
|
||||
);
|
||||
}
|
||||
+31
-43
@@ -25,51 +25,39 @@ macOS (see `docs/dev/macos-handcheck.md`).
|
||||
Not run when it was written (the guest was reserved): lint only (`py_compile`, `ruff`, the runner's
|
||||
157 unit tests pass).
|
||||
|
||||
## The golden guest has no OpenGL 2.0
|
||||
|
||||
The Windows gate (candidate 5) found that the bar cannot open a window in the golden guest:
|
||||
eframe's default renderer is `egui_glow`, the guest has the basic display adapter and QXL and no
|
||||
OpenGL driver, so Windows offers only the generic software OpenGL 1.1 of `opengl32.dll`, and the bar
|
||||
exits at start with `Error: egui_glow: OpenGL: egui_glow requires opengl 2.0+`
|
||||
(`komorebi-bar/src/windows/mod.rs`, the `run_native` error). The scenario therefore reports the
|
||||
window, stays-alive and daemon-restart checks as `skipped: guest has no OpenGL 2.0` when, and only
|
||||
when, the bar's own output says that (`extras/bar.py`, `classify`); any other early exit is a
|
||||
failure. The schema equality, the configuration read, `komorebic state` and `stop --bar` stay real
|
||||
checks. A skip is not a pass: the bar's runtime behaviour is unverified until the guest can draw.
|
||||
## Renderers: glow first, wgpu when there is no OpenGL
|
||||
|
||||
### Getting rendering into the guest (analysis, nothing added)
|
||||
The golden guest has no OpenGL 2.0 (the basic display adapter and QXL; Windows offers only the generic
|
||||
OpenGL 1.1), and eframe's `egui_glow` refuses that: the first gate of the `bar` scenario saw
|
||||
`Error: egui_glow: OpenGL: egui_glow requires opengl 2.0+` and the bar never opened a window.
|
||||
Decision D-coord-14: the Windows bar tries glow as before and, only when glow cannot make its context
|
||||
(`eframe::Error::OpenGL`, `Glutin` or `NoGlutinConfigs`), runs again with eframe's wgpu renderer, which
|
||||
draws through Direct3D 12 and finds the software adapter WARP (Windows 11 ships it in the Basic Render
|
||||
Driver) with no driver and no download (`run_with_fallback` in `komorebi-bar/src/windows/mod.rs`; the
|
||||
`wgpu` feature of `eframe` is in the Windows-only table of `komorebi-bar/Cargo.toml`, the bar core and
|
||||
the macOS bar do not have it). The bar logs `renderer: glow`, and on a fallback `renderer: glow failed
|
||||
(...); trying wgpu`. With both features compiled eframe's default renderer is wgpu, so the first attempt
|
||||
names `Renderer::Glow`: machines where glow works run exactly as before.
|
||||
|
||||
How the context is chosen: `komorebi-bar` uses `eframe` 0.33 with its default features, so only
|
||||
the glow renderer is compiled (glutin + `egui_glow`); `NativeOptions` is left at its defaults on
|
||||
Windows (the macOS bar sets its own), so the bar asks for a hardware OpenGL 2.0+ config through
|
||||
glutin, falls back to the Windows generic GDI implementation (1.1) and `egui_glow` refuses it.
|
||||
In the scenario:
|
||||
|
||||
1. Mesa llvmpipe `opengl32.dll` next to `komorebi-bar.exe` (the classic recipe: Mesa's
|
||||
`opengl32.dll` takes over from the system one for that process). Not possible from this flake:
|
||||
nixpkgs marks `pkgsCross.mingwW64.mesa` as an unsupported platform (`nix build --dry-run` refuses
|
||||
it), and `nixpkgs` has no Windows `opengl32sw.dll` (that file ships with Qt) or ANGLE. Building
|
||||
Mesa for mingw means porting its nix expression (swrast + llvm cross for mingw, a cross LLVM
|
||||
build) and carrying a binary of unknown license status in the image: days of work, hours of
|
||||
build, and the result is a third-party DLL in the test that real users do not run.
|
||||
2. A wgpu renderer with the Windows software adapter. Windows 11 ships WARP, the software
|
||||
Direct3D 12 rasteriser, in the Basic Render Driver, which the guest has; wgpu's DX12 backend
|
||||
finds it as an adapter, no download. In `eframe` this is the `wgpu` feature plus
|
||||
`NativeOptions { renderer: Renderer::Wgpu, .. }` (and `wgpu_options` with a fallback adapter if
|
||||
it does not pick WARP by itself). The sources of the wgpu stack (wgpu 27, naga, wgpu-hal,
|
||||
gpu-allocator, ash) are already in the local cargo registry because they are in `Cargo.lock`
|
||||
as optional dependencies of eframe, so it should build offline. Proposal, smallest first:
|
||||
in `komorebi-bar`'s `[target.'cfg(windows)'.dependencies]` ask for `eframe` with the `wgpu`
|
||||
feature, and at start: try glow as now; if `run_native` fails with the OpenGL message, run again
|
||||
with `Renderer::Wgpu` (the e2e then passes the window checks, and a user without OpenGL gets a
|
||||
bar instead of an error). Cost: about 60 more crates in `Cargo.lock` that are compiled for
|
||||
Windows only (cold build +3 to 5 minutes in CI, +8 to 12 MB in `komorebi-bar.exe`); a retry path
|
||||
that needs `NativeOptions` to be built twice; a new, untested code path for real users (low
|
||||
risk: it only runs where glow already failed). Without the fallback, a `KOMOREBI_BAR_RENDERER=wgpu`
|
||||
switch the scenario sets would keep users on glow and cost the same dependencies.
|
||||
3. ANGLE (EGL on Direct3D 11, itself on WARP) through `glutin`'s EGL support: needs
|
||||
`libEGL.dll`/`libGLESv2.dll`, which are not in nix either. Rejected.
|
||||
- the bar's window, stays-alive, daemon-restart and notify checks are real when either renderer opens the
|
||||
window; the scenario prints which one drew it;
|
||||
- only when both fail (the bar ends with `Error: glow: ...; wgpu: ...`) those checks are skipped, and the
|
||||
skip line names both errors (`skip ...: guest cannot draw: glow: ...; wgpu: ...`); the schema, the
|
||||
configuration read, `komorebic state` and `stop --bar` stay checks; any other early exit of the bar is a
|
||||
failure;
|
||||
- the bar is started with `RUST_LOG=info,wgpu_hal=debug,wgpu_core=warn` so `bar.out` keeps what wgpu says
|
||||
about its adapters (read it first when the window does not appear).
|
||||
|
||||
Recommendation: 2, with the glow-then-wgpu fallback, as its own revision with the e2e `bar`
|
||||
scenario as its gate (the window checks stop being skipped). Whether the guest's WARP accepts
|
||||
wgpu's DX12 device (feature level, no HLSL compiler problem for egui's shaders) can only be
|
||||
learned by running it; the first run should keep `RUST_LOG=wgpu_hal=debug` output in `bar.out`.
|
||||
Cost, measured: 622 -> 664 distinct crate versions in the Windows bar's dependency tree (+42), one new
|
||||
lock entry (`pollster` 0.4.0; the rest of the wgpu stack was already locked as optional dependencies of
|
||||
eframe). Not measured here (no nix build was run): compile time and the size of `komorebi-bar.exe`
|
||||
(estimate: a few minutes cold, 8 to 12 MB).
|
||||
|
||||
Risks: WARP may not accept egui's Direct3D 12 device or the transparent surface the bar asks for
|
||||
(`with_transparent(true)`; only the e2e gate can say); wgpu picks a hardware Vulkan/D3D12 adapter before
|
||||
WARP when there is one, so on a machine with a GPU but broken OpenGL the bar now uses that adapter; a
|
||||
second `run_native` on the same thread relies on eframe reusing its thread-local event loop (it does, by
|
||||
design, for reopening windows).
|
||||
+86
-2
@@ -1390,8 +1390,8 @@ monitors (`CycleMoveContainerToWorkspace`, `CycleSendContainerToWorkspace`, `Cyc
|
||||
`CycleMoveContainerToMonitor`, `CycleSendContainerToMonitor`, `FocusMonitorWorkspaceNumber`,
|
||||
`MoveContainerToMonitorWorkspaceNumber`, `SendContainerToMonitorWorkspaceNumber`) and the lock and
|
||||
unlock of a container by index. The one platform difference found, that Windows lets the pointer pick the
|
||||
monitor first for the empty, close and last-workspace commands (a probable omission on KDE and macOS,
|
||||
section 18), is the const `CommandHost::POINTER_PICKS_THE_MONITOR_FOR_ALL`, true only for Windows.
|
||||
monitor first for the empty, close, last-workspace and workspace-number commands (an omission on KDE and macOS,
|
||||
section 18), is gone: all three do it now (wip-u-ptr), so the const that held the difference was removed.
|
||||
|
||||
**What stays, and why** (identical across the three unless noted; each needs a `WindowManager` method
|
||||
or field, so moving them means moving `WindowManager`, the blockers of section 18):
|
||||
@@ -1409,3 +1409,87 @@ or field, so moving them means moving `WindowManager`, the blockers of section 1
|
||||
`WorkAreaOffset`, ...): thin calls of `WindowManager` methods that edit a workspace and re-layout, the
|
||||
same coupling;
|
||||
- queries, configuration, borders, animations, transparency, schema: statics and the platform.
|
||||
|
||||
## 23. Design note: thin events, a common vocabulary for `process_event` (not implemented)
|
||||
|
||||
Status: design only (D-coord-13 (c)). Nothing here is built; the event enums and handlers are unchanged. The variant lists below were read from the three `window_manager_event.rs` files; how each handler arm behaves was read at section 17 and not re-measured here.
|
||||
|
||||
**Today.** Each daemon has its own `WindowManagerEvent`, built from the platform notification:
|
||||
- Windows: `Destroy, FocusChange, Hide, Cloak, Minimize, Show, Uncloak, MoveResizeStart, MoveResizeEnd, MouseCapture, Maximize, Unmaximize, Manage, Unmanage, Raise, TitleUpdate`, most carrying `(WinEvent, Window)`.
|
||||
- KDE: `FocusChange, Show, Destroy, Minimize, Restore, TitleUpdate, FullscreenChange(bool), OutputChange, MaximizeChange(bool), Manage, Unmanage, MoveStart, MoveEnd, ResizeStart, ResizeEnd, ResizeStep, WorkspaceChange(desktop, idx), WorkspaceMove`, carrying `(SystemNotification, Window)`.
|
||||
- macOS: `FocusChange, Show, Destroy, Minimize, Restore, Manage, Unmanage, MoveStart, MoveEnd, ResizeStart, ResizeStep, ResizeEnd, SpaceChange, ScreenLock, ScreenUnlock`, carrying a process id and a window id instead of a `Window`.
|
||||
|
||||
Only `Destroy`, `Show` and `Minimize` exist under the same name on all three; `FocusChange`, `Manage`, `Unmanage`, `TitleUpdate` exist on Windows and KDE (macOS has the first three). The payloads differ: the platform notification, a `Window` or raw ids. So a shared `process_event` cannot match on today's enums.
|
||||
|
||||
**Proposal.** A small enum in `komorebi-core`, generic over the platform's window id and window type, that the platform adapter produces from its notification and that describes what happened, not how the OS said it:
|
||||
|
||||
```rust
|
||||
pub enum CoreEvent<W> {
|
||||
Appeared(W), // Show, Manage, Uncloak, WindowAdded
|
||||
Gone(W), // Destroy, Unmanage, Hide of a managed window
|
||||
Minimized(W), // Minimize, Cloak on Windows
|
||||
Restored(W), // Restore, Unminimize, Uncloak
|
||||
FocusMoved(W), // FocusChange
|
||||
MoveOrResize(Phase, W), // Start, Step, End for Windows MoveResize*, KDE and macOS Move/Resize
|
||||
FullscreenOrMaximize(W, bool),
|
||||
Retitled(W),
|
||||
OutputChanged(W),
|
||||
WorkspaceChanged(..), // KDE virtual desktop, macOS space: the platform tells which workspace
|
||||
}
|
||||
```
|
||||
|
||||
The Windows events that have no other-platform meaning (`MouseCapture`, `Raise`, `Cloak`/`Uncloak` distinctions) stay platform events: the adapter turns them into `CoreEvent` where they mean the same thing and handles the rest itself before or after. A handler for a `CoreEvent` is a `WindowManager` method with a platform hook for each decision the arms make today: `should_manage` (rules, already in `komorebi-rules` or in the daemon), whether the window is on this monitor, the border and transparency refresh after the layout, and the unmanaged-window check at the top (section 18 blocker; the router form is the target).
|
||||
|
||||
**What a shared handler looks like.** For `Gone(w)`: find the container holding `w`, `Workspace::remove_window` (shared), prune empty containers, `update`, then the border hook. For `Appeared(w)`: ask the `should_manage` hook, find the target monitor and workspace through the (shared) rules, `Workspace::new_container_for_window`, `update`, focus hook. For `Minimized(w)`: shared `Workspace` already hides and updates. These three account for the arms the three process_event files share most (sections 17 and 18).
|
||||
|
||||
**Prerequisites** (in order): the unmanaged-window-check converged to the router form on Windows (kfw); `WindowManager<P>` or at least a shared `WindowManagerState<P>` in core so the shared handler has a `self` (section 18 says the 60% threshold is not met yet); a `PlatformMonitorId`; the border calls behind hooks. Without the first two the shared handlers have nothing to run on.
|
||||
|
||||
**Risks.** The ordering of side effects inside each arm is part of today's behaviour, for instance Windows doing the border update before the focus event is forwarded, and KDE debouncing `ResizeStep`; a shared handler must keep the order per platform through hooks, or the change is a BEHAVIOUR change needing the Windows e2e, the KDE VM suites and the macOS hand check. `FocusChange` on macOS carries an optional window id and there is no `Window` yet at that point, so the `CoreEvent<W>` payload cannot always be a window.
|
||||
|
||||
**Decision wanted from the owner.** Whether to pursue this after `WindowManager<P>` lands; the gain is the event-handling arms (about a third of `process_event.rs` by line count at section 17) running natively on a stub for all three platforms.
|
||||
|
||||
## 22. After the macOS deep dedup (kfm, D-coord-13): the container API, the arms, and `update`
|
||||
|
||||
**Done.** (1) macOS `ContainerExt` is gone: every container call in the macOS daemon is the shared
|
||||
`Container::{add_window, load_focused_window, hide, restore}` with `workspace.hide_spot()`, a method of
|
||||
`Workspace` that is `P::hide_spot(self)` (`()` on KDE, `MacosHideSpot` on macOS). (2) the nine window
|
||||
manager functions that differed only in these calls (`add_window_to_container`,
|
||||
`cycle_container_window_in_direction`, `cycle_container_window_index_in_direction`,
|
||||
`focus_container_window`, `stack_all`, `monocle_on`, `monocle_off`, `cycle_monocle`, `transfer_window`)
|
||||
are now byte-identical in `komorebi-for-kde` and `komorebi-for-mac`; the `?` form replaced KDE's
|
||||
`let _ =` (equivalent, its operations always answer `Ok`). Measured with the function splitter: 76 of the
|
||||
92 function names that the two `window_manager.rs` share have the same text, and 1521 of KDE's 2713
|
||||
stripped lines are identical with macOS (56%, from 45% in section 20; the 60% bar needs the platform
|
||||
entry points of blocker 3). (3) `ToggleWorkspaceLayer`, `ResizeWindowAxis`, `SessionFloatRule`,
|
||||
`IgnoreRule` and `ReplaceConfiguration` are methods of the KDE names on macOS and the router arms are the
|
||||
KDE text; `Close`, `Minimize`, `DebugWindow` and `ManageRule` stay macOS's own arms (the foreground
|
||||
element and the role instead of the class; there is no KDE method to match).
|
||||
|
||||
**`update` is not adopted, and why (exact differences from `update_shared`).** Each is a reason, and
|
||||
the first two alone would make it unprovable:
|
||||
|
||||
1. **A scrolling workspace returns early.** macOS's `update` does `return self.arrange_scrolling(..)`
|
||||
inside the tile branch, so for a scrolling workspace it never reaches the closing
|
||||
`self.resize_dimensions.resize(container_count, None)` that `update_shared` always runs, and it places
|
||||
the windows itself (drag-step layout, `adopt_actual_sizes`, `hide_scrolling` at the display edge,
|
||||
the animator), not through one `place_container` per container. Folding it into `scrolling_layouts` plus
|
||||
`place_container` would change both the placement order and whether the resize dimensions are
|
||||
truncated for a scrolling workspace.
|
||||
2. **The SkyLight batch is wider.** macOS disables screen updates around the whole tile branch
|
||||
(monocle, scrolling and the container loop) and re-enables on every exit; a `begin_update` guard would
|
||||
start before `prune_duplicate_windows` and the container retain and end after the resize-dimensions
|
||||
fix-up, and would be taken when `tile` is false as well. Probably harmless, not provable.
|
||||
3. **Own `calculate_layouts`**: the same arrangement call as `update_shared`'s inline one (checked line by
|
||||
line), so this one alone would fold.
|
||||
4. **Unconditional clamp**: `clamp_to_work_area` runs for every non-scrolling layout; the shared
|
||||
`adjust_layout` hook can do that (as KDE's does).
|
||||
5. **No maximized branch**: the macOS workspace never has a `maximized_window` (no writer), so the shared
|
||||
branch is unreachable; `maximize_in_layout` is not needed.
|
||||
6. **Placement errors are logged and the next window is placed** (`tracing::warn!`): a `place_container`
|
||||
hook can swallow them as KDE's does.
|
||||
7. **No second pass and no stackbar**: `end_update` answers `Pass::Done`.
|
||||
|
||||
Items 3 to 7 would fold with hooks; 1 and 2 are the blockers, and 1 is the owner's decision: either the
|
||||
macOS scrolling placement becomes the `scrolling_layouts` and `place_container` hooks (and the
|
||||
truncation of the resize dimensions is accepted for a scrolling workspace, which is a behaviour change),
|
||||
or `update` stays macOS's.
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
Findings of the consolidation reviews and tests that are NOT fixed because whether they are bugs, or how to fix them, is a decision for the owner. Each has the evidence, why it may or may not be a bug, the platforms, and a proposed fix. Paths are relative to the repository root at the time of writing and may have moved.
|
||||
|
||||
## 1. KDE FocusWorkspaceNumber, FocusWorkspaceNumbers and FocusLastWorkspace skip the pointer-monitor preamble
|
||||
## 1. RESOLVED (wip-u-ptr): KDE FocusWorkspaceNumber, FocusWorkspaceNumbers and FocusLastWorkspace skipped the pointer-monitor preamble
|
||||
|
||||
- **Resolution**: the owner approved Windows behaviour for all platforms. The preamble now runs for all three daemons in the shared `komorebi_core::command` functions (`focus_workspace_number`, `focus_workspace_numbers`, `focus_last_workspace`, and the others). KDE is covered by `komorebi-for-kde/komorebi/tests/pointer_monitor.rs`, core by `crates/komorebi-core/tests/commands.rs`. Owed: KDE VM commands and workspace-switch, macOS hand check H1 (docs/dev/macos-handcheck.md). The text below is the original finding.
|
||||
|
||||
- **Evidence**: komorebi-for-kde/komorebi/src/process_command.rs lines 1245-1277: the arms for the three messages call `focus_workspace` on the focused monitor directly. The Windows daemon (komorebi/src/process_command.rs:972-987 for `FocusWorkspaceNumber`, and lines about 2185 and 2215 for the helpers behind `FocusLastWorkspace` and `FocusWorkspaceNumbers`) first checks `monitor_idx_from_current_pos()`: when the pointer is on another monitor whose focused workspace is empty, that monitor becomes the focused one. KDE has the same preamble only in `cycle_focus_workspace` (line 897-909).
|
||||
- **Why it may be a bug**: on a secondary monitor with an empty workspace and the pointer on it, `focus-workspace 2` switches the workspace of the monitor that was focused before, not the one the user is pointing at, unlike on Windows and unlike KDE's own `cycle-focus-workspace`. **Why not**: KWin may not report an empty monitor as pointed at the same way; the KDE tests do not cover it, so it may have been left out on purpose.
|
||||
|
||||
@@ -97,6 +97,8 @@ timeout. Until then H5 documents the hang.
|
||||
| 11(iii) Workspace: `refactor(mac): the daemon's Workspace is komorebi_core::Workspace<MacosPlatform>` (see `jj log -r wip-u-kfm2`) | About 50 workspace functions (container and focus operations, placement, resize constraints, window lookups, floating helpers, the stack and monocle operations that hide windows) are now the shared ones; `hide`, `new_container_for_window` and the stack functions pass the monitor's corner through `MacosPlatform::hide_spot` (kept in `MacosWorkspaceState`, set by the monitor with the globals), and `hide` passes the display bounds for the containers through `hide_spot_on_display`. macOS's own `update`, `apply_wallpaper`, `restore`, `remove_window`, `load_static_config`, `prune_duplicate_windows`, `visible_window_details`, `reap_invalid_windows_for_application`, `restore_windows`, `calculate_layouts` and `set_scrolling_columns` are `WorkspaceExt`; the scrolling methods are `WorkspaceScrolling`. | `cargo test` first (the workspace, scrolling and window_manager tests). Then: stack and unstack, switch workspaces both ways (each stack shows its front window, the hidden ones are in their monitor's corner), toggle monocle and back, float and unfloat a window, cycle the monocle container, move a window to another workspace, move a container across monitors; with a different `window_hiding_position` on each monitor check each monitor's windows park in their own corner and that a floating window that overhangs the edge of a display is still parked on its own display. `komorebic state` keys of a workspace are unchanged (pinned by `state_pin`). Scrolling layout: focus, move, consume and expel, pan, resize a column. |
|
||||
| 11(iii) Monitor: `refactor(mac): the daemon's Monitor is komorebi_core::Monitor<MacosPlatform>` (see `jj log -r wip-u-kfm2`) | The monitor is the shared generic type; the corner (`window_hiding_position`) is the platform's flattened `extra` (written last, as before), the constructors, `update_*_globals`, `load_focused_workspace`, `move_container_to_workspace(1)`, `add_container_with_direction`, `hide_unfocused_workspaces` and `restore_focused_workspace` are `MonitorExt`; `focus_workspace`, `add_container`, `remove_workspace*`, `ensure_workspace_count` and the name and layout lookups are the shared ones. The monitor gives its workspaces the corner through `workspace.state` when it updates their globals. | `cargo test` (monitor tests, `state_pin`). By hand: `komorebic state | jq '.monitors.elements[0] | keys_unsorted'` is the same list as before with `window_hiding_position` last; switch workspaces on each monitor (hide and restore of the whole workspace), focus-workspace by index and by name, move a container to another workspace and to another monitor, unplug and replug a display (the monitor and its workspaces are rebuilt through `Monitor::new` and `update_all_workspace_globals`), a config with `window_hiding_position` per monitor. |
|
||||
| `wip-u-kfm3` registry fixes (see `jj log -r wip-u-kfm3`) | The registry keeps inert application copies (no blocking Accessibility call when an entry is dropped), a window is registered when its observer is attached, a clone being dropped no longer deregisters its window, `forget_pid` runs ahead of the pause and other-space returns, and the application reaper forgets what it reaps. Nothing reads the registry except the unused `MacosBackend`. | H3, H4, H6, H7 above, and the usual walk-through: no change in what the daemon does is expected. |
|
||||
| deep dedup 1: `refactor(mac): the daemon uses the shared Container API with the hide spot` (see `jj log -r wip-u-mac-deep`) | `ContainerExt` (`add_window_at`, `load_focused_window_at`, `hide_on`, `restore_focused_window`) is gone: every call is the shared `Container::{add_window, load_focused_window, hide, restore}` with `workspace.hide_spot()`. `monocle_on` and `cycle_monocle` took the corner from the monitor (`monitor.extra`) and now take it from the workspace (`workspace.state`), which the monitor writes with the globals; `restore()` now skips the Accessibility call under `cfg!(test)`. | `cargo test`; then H1 (hide spot) and: toggle monocle on a workspace with two containers on a monitor with `window_hiding_position: BottomRight` (every other container parks in that corner), cycle the monocle container, stack with `komorebic stack`/`stack-all`, `cycle-stack`, `add-window-to-container`, switch workspaces. Change the monitor's `window_hiding_position` in the config, reload, and toggle monocle at once: the corner must be the new one. |
|
||||
| deep dedup 2: `refactor(mac): five router arms are methods with the KDE names` | `ToggleWorkspaceLayer`, `ResizeWindowAxis`, `SessionFloatRule`, `IgnoreRule` and `ReplaceConfiguration` call `toggle_workspace_layer`, `resize_window_axis`, `add_session_float_rule`, `add_ignore_rule(identifier, id: &str)` and `replace_configuration(&PathBuf)`, with the bodies the arms had (a pure move; the router arms are now the KDE text). `id` of the ignore rule is a `&str`, compared with `==`. | `cargo test`; by hand: `komorebic toggle-workspace-layer` twice (tiling to floating and back: a window of the layer is focused, the others hide at the corner and come back), `resize-axis horizontal|vertical increase|decrease`, `komorebic session-float-rule` on a window, `komorebic ignore-rule exe <name>` and `ignore-rule title/class` (the matching windows leave the workspaces), `komorebic replace-configuration <komorebi.json>` (the daemon restarts its windows under the new config; with a broken file it is left alone). |
|
||||
|
||||
Revisions in section B change no behaviour on purpose (rename, move, route); they still need the sections C walk-through, because a mechanical mistake would show there.
|
||||
|
||||
@@ -164,3 +166,9 @@ Type-check and clippy only; nothing here ran on a Mac. The settings now live in
|
||||
1. **S3 groups (paddings, floating aspect ratio, `layout_defaults`, `display_index_preferences`).** Config with `default_workspace_padding` 20 and `default_container_padding` 15: tiles 20 px from the work area, 15 apart. Reload with the key dropped: padding stays (merge); set it to 5 and reload: 5. `layout_defaults`: set, reload, workspaces use it; remove and reload: they fall back (the key resets). Aspect ratio: `toggle-float` with centring uses the configured ratio; remove the key and reload: 4:3 (Standard). `display_index_preference 0 <serial>`: monitor order follows it. Reload during a drag or workspace switch: no one-frame flash of half-new padding.
|
||||
2. **S5 animation (BEHAVIOUR: one snapshot for enabled, duration, style and fps).** Animation on (`komorebic animation true`), switch workspace: transition plays. While a transition runs, `komorebic animation-duration 1000`, then `animation-style`, then `animation false`: the running transition is not torn (no mix of old duration with new style), the next one follows the new values. Per-kind: `animation true --movement`, `animation false` (global): per-kind values are cleared by a global value, so movement is off again. Reload a file with `"animation": {"enabled": {"movement": true}}`: only movement animates and the global flag is untouched; reload a file with `"animation": {"enabled": true}` (no fps): fps back to 60; reload a file with no animation block: all animation settings keep their values. `komorebic animation-fps 30` then watch frame cadence. Stack a window (`stack`): no animation during the stack (the `suspend()` counter, unchanged), and animation is back after it, including after a stack command that fails.
|
||||
3. The border and transparency groups (S6, S4) are not moved on macOS: transparency does not exist there.
|
||||
|
||||
## H. Pointer picks the monitor (wip-u-ptr), appended by the KDE agent
|
||||
|
||||
Type-check and clippy only (fake CC); nothing here ran on a Mac.
|
||||
|
||||
1. **Pointer on an empty workspace of another monitor (BEHAVIOUR).** With two displays, an empty workspace on the second display and the pointer over it while the first display is focused: `komorebic focus-workspace 1`, `komorebic focus-workspaces 1` and `komorebic focus-last-workspace` first focus the display under the pointer, then switch its workspace (before, `focus-workspace` and `focus-workspaces` acted on the focused display). With the pointer on the focused display nothing changes.
|
||||
@@ -31,6 +31,7 @@ BAR_CONFIG = "C:\\e2e\\bar.json"
|
||||
BAR_OUTPUT = "C:\\e2e\\bar.out"
|
||||
# the title eframe gives the window (`run_native("komorebi-bar", ...)`)
|
||||
ANSI = re.compile(r"\x1b\[[0-9;]*m")
|
||||
BAR_LOG = "info,wgpu_hal=debug,wgpu_core=warn"
|
||||
BAR_TITLE = "komorebi-bar"
|
||||
# how long the bar must keep running, in seconds
|
||||
ALIVE_SECONDS = 15
|
||||
@@ -104,23 +105,34 @@ def _alive_for(platform: WindowsPlatform, seconds: float) -> bool:
|
||||
return bool(_bar_pids(platform))
|
||||
|
||||
|
||||
# what the bar prints when eframe cannot make a window for lack of OpenGL (komorebi-bar's
|
||||
# `run_native` error), as the gate printed it: "egui_glow requires opengl 2.0+"
|
||||
# what the bar prints when glow cannot make its context (komorebi-bar's `run_native` error), as the gate
|
||||
# printed it: "egui_glow requires opengl 2.0+". The bar then tries wgpu (Direct3D 12, WARP) and, when that
|
||||
# fails too, ends with "glow: <error>; wgpu: <error>".
|
||||
NO_OPENGL_TEXT = "requires opengl"
|
||||
NO_OPENGL = "guest has no OpenGL 2.0"
|
||||
|
||||
|
||||
def classify(output: str) -> str | None:
|
||||
"""What the bar's own output says about its start: "no_opengl" (it could not make a
|
||||
window for lack of OpenGL), "failed" (it ended with any other error: a configuration it
|
||||
"""What the bar's own output says about its start: "no_renderer" (neither glow nor wgpu
|
||||
could make a window: no OpenGL 2.0 and no usable Direct3D 12 adapter), "failed" (it ended with any other error: a configuration it
|
||||
could not read, a crash) or None (no error, it runs)."""
|
||||
if "Error:" not in output and "panicked" not in output:
|
||||
return None
|
||||
if NO_OPENGL_TEXT in output.lower():
|
||||
return "no_opengl"
|
||||
return "no_renderer"
|
||||
return "failed"
|
||||
|
||||
|
||||
def _renderer_errors(output: str) -> str:
|
||||
"""The line that names what glow and wgpu said, for a skip."""
|
||||
for line in output.splitlines():
|
||||
if "wgpu:" in line and "glow:" in line:
|
||||
return line.strip()
|
||||
for line in output.splitlines():
|
||||
if NO_OPENGL_TEXT in line.lower():
|
||||
return f"glow: {line.strip()}; (no wgpu attempt: an older bar)"
|
||||
return "no renderer"
|
||||
|
||||
|
||||
def _bar_output(platform: WindowsPlatform) -> str:
|
||||
try:
|
||||
text = platform.agent_get_file(BAR_OUTPUT).decode(errors="replace")
|
||||
@@ -135,7 +147,7 @@ def _started(platform: WindowsPlatform) -> bool:
|
||||
|
||||
|
||||
def _outcome(platform: WindowsPlatform) -> str:
|
||||
"""Waits for the bar's window or its end: "running" (the window is there), "no_opengl",
|
||||
"""Waits for the bar's window or its end: "running" (the window is there), "no_renderer",
|
||||
"failed", or "timeout" (neither within a minute)."""
|
||||
deadline = time.monotonic() + 60 * platform._scale
|
||||
while time.monotonic() < deadline:
|
||||
@@ -172,8 +184,10 @@ def run(platform: WindowsPlatform, checks: Checks, clients: list[Client]) -> Non
|
||||
local = platform._out / "bar.json"
|
||||
local.write_text(json.dumps(CONFIG, indent=2))
|
||||
platform._agent.put_file(local, BAR_CONFIG)
|
||||
# the log of the first run keeps what wgpu says about its adapters
|
||||
platform.agent_spawn(
|
||||
"cmd", "/c", f"{BAR_BINARY} --config {BAR_CONFIG} > {BAR_OUTPUT} 2>&1"
|
||||
"cmd", "/c",
|
||||
f"set RUST_LOG={BAR_LOG}&& {BAR_BINARY} --config {BAR_CONFIG} > {BAR_OUTPUT} 2>&1",
|
||||
)
|
||||
|
||||
checks.check("the bar process starts", platform.wait_for(lambda: _started(platform), timeout=30))
|
||||
@@ -188,16 +202,17 @@ def run(platform: WindowsPlatform, checks: Checks, clients: list[Client]) -> Non
|
||||
outcome != "failed" and "found configuration file" in text,
|
||||
)
|
||||
|
||||
if outcome == "no_opengl":
|
||||
# the golden guest has no OpenGL 2.0 (basic display and QXL, no software opengl32), so
|
||||
# eframe cannot make the window: not what a change of the bar did, and not a pass
|
||||
if outcome == "no_renderer":
|
||||
# the bar tried glow and then wgpu and neither could make a window: not what a change of the
|
||||
# bar did, and not a pass
|
||||
reason = f"guest cannot draw: {_renderer_errors(text)}"
|
||||
for what in (
|
||||
f"the bar's window titled {BAR_TITLE!r} appears",
|
||||
f"the bar keeps running for {ALIVE_SECONDS} s",
|
||||
"the bar is still running after the daemon stopped",
|
||||
"the bar runs on after the daemon is back",
|
||||
):
|
||||
checks.skip(what, NO_OPENGL)
|
||||
checks.skip(what, reason)
|
||||
checks.check(
|
||||
"`komorebic state` answers after the bar has started",
|
||||
platform.wait_for(lambda: platform.komorebic_status("state")[0] == 0),
|
||||
@@ -215,6 +230,8 @@ def run(platform: WindowsPlatform, checks: Checks, clients: list[Client]) -> Non
|
||||
platform.start_komorebi()
|
||||
return
|
||||
|
||||
used = "wgpu" if "trying wgpu" in text else "glow"
|
||||
print(f" the bar draws with {used}")
|
||||
window = _bar_window(platform)
|
||||
checks.check(f"the bar's window titled {BAR_TITLE!r} appears", window is not None)
|
||||
if window is not None:
|
||||
|
||||
@@ -12,8 +12,8 @@ PARSE = (
|
||||
)
|
||||
|
||||
|
||||
def test_no_opengl_is_told_from_other_errors():
|
||||
assert bar.classify(GL) == "no_opengl"
|
||||
def test_no_renderer_is_told_from_other_errors():
|
||||
assert bar.classify(GL) == "no_renderer"
|
||||
|
||||
|
||||
def test_any_other_error_is_a_failure():
|
||||
@@ -29,3 +29,22 @@ def test_a_bar_that_prints_no_error_runs():
|
||||
def test_the_test_configuration_is_plain_json_values():
|
||||
# the untagged MouseMessage::Command is a string
|
||||
assert isinstance(bar.CONFIG["mouse"]["on_middle_click"], str)
|
||||
|
||||
|
||||
BOTH = (
|
||||
"INFO komorebi_bar::windows: renderer: glow\n"
|
||||
" WARN komorebi_bar::windows: renderer: glow failed (egui_glow: OpenGL: egui_glow requires opengl 2.0+. ); trying wgpu\n"
|
||||
"Error: glow: egui_glow: OpenGL: egui_glow requires opengl 2.0+. ; wgpu: Failed to find a suitable adapter\n"
|
||||
)
|
||||
|
||||
|
||||
def test_both_renderers_failing_is_reported_with_both_errors():
|
||||
assert bar.classify(BOTH) == "no_renderer"
|
||||
line = bar._renderer_errors(BOTH)
|
||||
assert "glow:" in line and "wgpu:" in line
|
||||
|
||||
|
||||
def test_a_bar_that_fell_back_to_wgpu_and_runs_is_not_an_error():
|
||||
# the warning about glow is not an "Error:" line
|
||||
ran = BOTH.splitlines()[0] + "\n" + BOTH.splitlines()[1] + "\nINFO wgpu_hal: adapter WARP\n"
|
||||
assert bar.classify(ran) is None
|
||||
@@ -40,6 +40,9 @@ tracing-subscriber = { workspace = true }
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
komorebi-themes = { path = "../komorebi-themes", default-features = false }
|
||||
egui_extras = { workspace = true }
|
||||
# a second renderer, wgpu (Direct3D 12, which has the software adapter WARP), for a machine where OpenGL 2.0 is not
|
||||
# there; glow stays the first (see `renderer_attempts` in windows/mod.rs). Windows only: the macOS bar has no use for it
|
||||
eframe = { workspace = true, features = ["wgpu"] }
|
||||
netdev = "0.46"
|
||||
regex = "1"
|
||||
sysinfo = { workspace = true }
|
||||
|
||||
@@ -273,10 +273,7 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
.with_transparent(true)
|
||||
.with_taskbar(false);
|
||||
|
||||
let native_options = eframe::NativeOptions {
|
||||
viewport: viewport_builder,
|
||||
..Default::default()
|
||||
};
|
||||
let native_options = |renderer| native_options(viewport_builder.clone(), renderer);
|
||||
|
||||
if let Some(rect) = &work_area_offset {
|
||||
komorebi_client::send_message(&SocketMessage::MonitorWorkAreaOffset(monitor_index, *rect))?;
|
||||
@@ -307,10 +304,12 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
|
||||
tracing::info!("watching configuration file for changes");
|
||||
|
||||
eframe::run_native(
|
||||
"komorebi-bar",
|
||||
native_options,
|
||||
Box::new(|cc| {
|
||||
let app_creator = |tx_gui: crossbeam_channel::Sender<KomorebiEvent>,
|
||||
rx_gui: crossbeam_channel::Receiver<KomorebiEvent>,
|
||||
rx_config: crossbeam_channel::Receiver<KomobarConfig>,
|
||||
config: KomobarConfig|
|
||||
-> eframe::AppCreator<'static> {
|
||||
Box::new(move |cc| {
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
@@ -395,7 +394,62 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
});
|
||||
|
||||
Ok(Box::new(Komobar::new(cc, rx_gui, rx_config, config)))
|
||||
}),
|
||||
})
|
||||
};
|
||||
|
||||
run_with_fallback(
|
||||
native_options,
|
||||
// a creator for each attempt: the first is never run when its renderer fails to start, so the
|
||||
// second gets what it would have had (the channels are shared, the configuration is a copy)
|
||||
|_renderer| app_creator(tx_gui.clone(), rx_gui.clone(), rx_config.clone(), config.clone()),
|
||||
)
|
||||
.map_err(|error| color_eyre::eyre::Error::msg(error.to_string()))
|
||||
}
|
||||
|
||||
/// The options of a window drawn by `renderer`. The renderer is always named: with eframe's `glow` and `wgpu`
|
||||
/// features both compiled, its default is wgpu, and glow has to stay the first choice.
|
||||
fn native_options(viewport: ViewportBuilder, renderer: eframe::Renderer) -> eframe::NativeOptions {
|
||||
eframe::NativeOptions {
|
||||
viewport,
|
||||
renderer,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `error` is the renderer failing to get a graphics context (what a machine without OpenGL 2.0
|
||||
/// does to glow: "egui_glow requires opengl 2.0+"), so that the other renderer is worth a try.
|
||||
fn is_context_failure(error: &eframe::Error) -> bool {
|
||||
matches!(
|
||||
error,
|
||||
eframe::Error::OpenGL(_) | eframe::Error::Glutin(_) | eframe::Error::NoGlutinConfigs(..)
|
||||
)
|
||||
}
|
||||
|
||||
/// Runs the bar with glow, as always; only when glow cannot make its context (no OpenGL 2.0), runs it again with
|
||||
/// wgpu, which draws through Direct3D 12 and finds the software adapter (WARP) when there is no GPU driver.
|
||||
fn run_with_fallback(
|
||||
options: impl Fn(eframe::Renderer) -> eframe::NativeOptions,
|
||||
creator: impl Fn(eframe::Renderer) -> eframe::AppCreator<'static>,
|
||||
) -> color_eyre::Result<()> {
|
||||
tracing::info!("renderer: glow");
|
||||
match eframe::run_native("komorebi-bar", options(eframe::Renderer::Glow), creator(eframe::Renderer::Glow)) {
|
||||
Err(error) if is_context_failure(&error) => {
|
||||
tracing::warn!("renderer: glow failed ({error}); trying wgpu");
|
||||
eframe::run_native("komorebi-bar", options(eframe::Renderer::Wgpu), creator(eframe::Renderer::Wgpu))
|
||||
.map_err(|wgpu| {
|
||||
color_eyre::eyre::Error::msg(format!("glow: {error}; wgpu: {wgpu}"))
|
||||
})
|
||||
}
|
||||
result => result.map_err(|error| color_eyre::eyre::Error::msg(error.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_bar_failing_to_start_is_not_a_reason_to_try_the_other_renderer() {
|
||||
let creation = eframe::Error::AppCreation("no".into());
|
||||
assert!(!is_context_failure(&creation));
|
||||
}
|
||||
}
|
||||
@@ -1125,21 +1125,10 @@ impl WindowManager {
|
||||
}
|
||||
SocketMessage::FocusLastWorkspace => self.focus_last_workspace()?,
|
||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||
if self.focused_workspace_idx().unwrap_or_default() != workspace_idx {
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
}
|
||||
komorebi_core::focus_workspace_number(self, workspace_idx)?
|
||||
}
|
||||
SocketMessage::FocusWorkspaceNumbers(workspace_idx) => {
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
|
||||
for (i, monitor) in self.monitors_mut().iter_mut().enumerate() {
|
||||
if i != focused_monitor_idx {
|
||||
monitor.focus_workspace(workspace_idx)?;
|
||||
monitor.load_focused_workspace(false)?;
|
||||
}
|
||||
}
|
||||
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
komorebi_core::focus_workspace_numbers(self, workspace_idx)?
|
||||
}
|
||||
SocketMessage::FocusMonitorWorkspaceNumber(monitor_idx, workspace_idx) => {
|
||||
komorebi_core::focus_monitor_workspace_number(self, monitor_idx, workspace_idx)?
|
||||
@@ -2052,6 +2041,16 @@ impl komorebi_core::CommandHost for WindowManager {
|
||||
WindowManager::focus_workspace(self, idx)
|
||||
}
|
||||
|
||||
fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()> {
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
.ok_or_eyre("there is no monitor at this index")?;
|
||||
monitor.focus_workspace(workspace_idx)?;
|
||||
monitor.load_focused_workspace(false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn move_container_to_workspace(
|
||||
&mut self,
|
||||
idx: usize,
|
||||
|
||||
@@ -48,6 +48,10 @@
|
||||
//!
|
||||
//! [`listen_for_commands`]: crate::process_command::listen_for_commands
|
||||
|
||||
// the text of the container calls is the same as on macOS, where the hide spot is a value: here it
|
||||
// is `()`, and binding it is how the two stay identical
|
||||
#![allow(clippy::let_unit_value)]
|
||||
|
||||
use crate::DATA_DIR;
|
||||
use crate::HIDDEN_WINDOWS;
|
||||
use crate::LibraryError;
|
||||
@@ -1320,8 +1324,10 @@ impl WindowManager {
|
||||
workspace.move_window_to_container(adjusted_new_index)?;
|
||||
}
|
||||
}
|
||||
|
||||
let spot = workspace.hide_spot();
|
||||
if changed_focus && let Some(container) = workspace.focused_container_mut() {
|
||||
let _ = container.load_focused_window(());
|
||||
container.load_focused_window(spot)?;
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
@@ -1425,6 +1431,7 @@ impl WindowManager {
|
||||
tracing::info!("cycling container windows");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
|
||||
let container = self.focused_container_mut()?;
|
||||
|
||||
@@ -1439,7 +1446,7 @@ impl WindowManager {
|
||||
let next_idx = direction.next_idx(current_idx, len);
|
||||
|
||||
container.focus_window(next_idx);
|
||||
let _ = container.load_focused_window(());
|
||||
container.load_focused_window(spot)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -1631,8 +1638,9 @@ impl WindowManager {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.new_monocle_container()?;
|
||||
|
||||
let spot = workspace.hide_spot();
|
||||
for container in workspace.containers_mut() {
|
||||
let _ = container.hide(None, ());
|
||||
container.hide(None, spot)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -1651,7 +1659,7 @@ impl WindowManager {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
for container in workspace.containers_mut() {
|
||||
let _ = container.restore();
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
workspace.reintegrate_monocle_container()
|
||||
@@ -1678,8 +1686,9 @@ impl WindowManager {
|
||||
self.focused_workspace_mut()?
|
||||
.cycle_monocle_container(direction)?;
|
||||
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
for container in self.focused_workspace_mut()?.containers_mut() {
|
||||
let _ = container.hide(None, ());
|
||||
container.hide(None, spot)?;
|
||||
}
|
||||
|
||||
self.update_focused_workspace(true, true)
|
||||
@@ -2811,6 +2820,7 @@ impl WindowManager {
|
||||
tracing::info!("cycling container window index");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
@@ -2831,7 +2841,7 @@ impl WindowManager {
|
||||
container.windows_mut().swap(current_idx, next_idx);
|
||||
|
||||
container.focus_window(next_idx);
|
||||
let _ = container.load_focused_window(());
|
||||
container.load_focused_window(spot)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -2853,6 +2863,7 @@ impl WindowManager {
|
||||
tracing::info!("focusing container window at index {idx}");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
@@ -2873,7 +2884,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
container.focus_window(idx);
|
||||
let _ = container.load_focused_window(());
|
||||
container.load_focused_window(spot)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -2893,6 +2904,7 @@ impl WindowManager {
|
||||
tracing::info!("stacking all windows on workspace");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let spot = workspace.hide_spot();
|
||||
|
||||
let mut focused_hwnd = None;
|
||||
if let Some(container) = workspace.focused_container()
|
||||
@@ -2920,7 +2932,7 @@ impl WindowManager {
|
||||
&& let Some(w_idx_to_focus) = c.idx_for_window(hwnd)
|
||||
{
|
||||
c.focus_window(w_idx_to_focus);
|
||||
let _ = c.load_focused_window(());
|
||||
c.load_focused_window(spot)?;
|
||||
}
|
||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||
}
|
||||
@@ -3893,7 +3905,7 @@ impl WindowManager {
|
||||
.ok_or_eyre("there is no workspace for this monitor")?;
|
||||
|
||||
for container in origin_workspace.containers_mut() {
|
||||
let _ = container.restore();
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
origin_workspace.reintegrate_monocle_container()?;
|
||||
@@ -3906,15 +3918,46 @@ impl WindowManager {
|
||||
target_container_idx,
|
||||
),
|
||||
)?;
|
||||
// TODO: don't think this is needed on macOS
|
||||
// After we restore the origin workspace, some windows that were cloacked
|
||||
// by the monocle might now be uncloacked which would trigger a workspace
|
||||
// reconciliation since the focused monitor would be different from origin.
|
||||
// That workspace reconciliation would focus the window on the origin monitor.
|
||||
// So we need to ignore the uncloak events produced by the origin workspace
|
||||
// restore to avoid that issue.
|
||||
// self.uncloack_to_ignore = uncloack_amount;
|
||||
}
|
||||
// TODO: this probably won't be used on macOS
|
||||
} else if origin_workspace
|
||||
.maximized_window
|
||||
.as_ref()
|
||||
.map(|max| max.id == window_id)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
// A maximized window is in no container, so there is none to transfer: it stays where
|
||||
// it is
|
||||
// Moving maximized_window
|
||||
// TODO: not sure if we'll support maximized windows on macOS
|
||||
// if let Some(maximized_idx) = origin_workspace.maximized_window_restore_idx {
|
||||
// self.focus_monitor(origin_monitor_idx)?;
|
||||
// let origin_monitor = self
|
||||
// .focused_monitor_mut()
|
||||
// .ok_or_eyre("there is no origin monitor")?;
|
||||
// origin_monitor.focus_workspace(origin_workspace_idx)?;
|
||||
// self.unmaximize_window()?;
|
||||
// self.focus_monitor(target_monitor_idx)?;
|
||||
// let target_monitor = self
|
||||
// .focused_monitor_mut()
|
||||
// .ok_or_eyre("there is no target monitor")?;
|
||||
// target_monitor.focus_workspace(target_workspace_idx)?;
|
||||
//
|
||||
// self.transfer_container(
|
||||
// (origin_monitor_idx, origin_workspace_idx, maximized_idx),
|
||||
// (
|
||||
// target_monitor_idx,
|
||||
// target_workspace_idx,
|
||||
// target_container_idx,
|
||||
// ),
|
||||
// )?;
|
||||
// }
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
//! The pointer picks the monitor: `focus-workspace`, `focus-workspaces`, `focus-last-workspace`,
|
||||
//! `cycle-empty-workspace`, `close-workspace` and the cycles act on the monitor the pointer is on
|
||||
//! when the workspace shown there is empty (the behaviour Windows always had; see
|
||||
//! docs/dev/known-issues.md item 1), against an in-memory desktop with two monitors side by side.
|
||||
//!
|
||||
//! Window ids are in the 33_000s.
|
||||
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
use komorebi::backend::with_backend;
|
||||
use komorebi::core::Rect;
|
||||
use komorebi::core::SocketMessage;
|
||||
use komorebi::window::Window;
|
||||
use komorebi::window_manager::WindowManager;
|
||||
use komorebi::window_manager_event::KWinNotification;
|
||||
use komorebi::window_manager_event::SystemNotification;
|
||||
use komorebi::window_manager_event::WindowManagerEvent;
|
||||
use std::sync::Arc;
|
||||
|
||||
const RIGHT: u32 = 2;
|
||||
|
||||
fn added(id: u32) -> WindowManagerEvent {
|
||||
WindowManagerEvent::Show(
|
||||
SystemNotification::KWin(KWinNotification::WindowAdded),
|
||||
Window::from(id),
|
||||
)
|
||||
}
|
||||
|
||||
/// The bounds of the monitor on the right, which is also its work area
|
||||
fn right_half() -> Rect {
|
||||
Rect {
|
||||
left: 1920,
|
||||
top: 0,
|
||||
right: 1920,
|
||||
bottom: 1080,
|
||||
}
|
||||
}
|
||||
|
||||
/// A window manager over a fake desktop with the monitor of `with_one_monitor` on the left and a
|
||||
/// second one on the right
|
||||
fn two_monitors() -> (Arc<FakeBackend>, WindowManager) {
|
||||
let fake = FakeBackend::with_one_monitor();
|
||||
fake.add_monitor(RIGHT, "Virtual-1", right_half(), right_half());
|
||||
let fake = Arc::new(fake);
|
||||
let (_sender, receiver) = crossbeam_channel::bounded(1);
|
||||
// unix socket paths are limited to ~104 bytes on macOS, which the temp dir alone can exceed
|
||||
static NEXT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
let socket = std::path::PathBuf::from(format!(
|
||||
"/tmp/kmm-{}-{}.sock",
|
||||
std::process::id(),
|
||||
NEXT.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
|
||||
));
|
||||
|
||||
let wm = with_backend(fake.clone(), || {
|
||||
let mut wm = WindowManager::new(receiver, Some(socket)).unwrap();
|
||||
wm.init().unwrap();
|
||||
wm
|
||||
});
|
||||
|
||||
(fake, wm)
|
||||
}
|
||||
|
||||
fn open_on_the_left(fake: &Arc<FakeBackend>, wm: &mut WindowManager, id: u32) {
|
||||
fake.open_window(id, "foot", "foot", &format!("terminal {id}"));
|
||||
with_backend(fake.clone(), || wm.process_event(added(id))).unwrap();
|
||||
}
|
||||
|
||||
fn send(
|
||||
fake: &Arc<FakeBackend>,
|
||||
wm: &mut WindowManager,
|
||||
message: SocketMessage,
|
||||
) -> color_eyre::Result<()> {
|
||||
with_backend(fake.clone(), || wm.process_command(message, Vec::new()))
|
||||
}
|
||||
|
||||
/// The left monitor has a window and the focus; the right one is empty and has the pointer
|
||||
fn pointer_on_the_empty_monitor() -> (Arc<FakeBackend>, WindowManager) {
|
||||
let (fake, mut wm) = two_monitors();
|
||||
open_on_the_left(&fake, &mut wm, 33_001);
|
||||
fake.set_cursor(2500, 300);
|
||||
assert_eq!(wm.focused_monitor_idx(), 0);
|
||||
(fake, wm)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_workspace_switches_the_monitor_under_the_pointer_when_it_is_empty() {
|
||||
let (fake, mut wm) = pointer_on_the_empty_monitor();
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::FocusWorkspaceNumber(1)).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
wm.focused_monitor_idx(),
|
||||
1,
|
||||
"the pointer's monitor is focused first"
|
||||
);
|
||||
assert_eq!(wm.monitors()[1].focused_workspace_idx(), 1);
|
||||
assert_eq!(
|
||||
wm.monitors()[0].focused_workspace_idx(),
|
||||
0,
|
||||
"and the monitor that had the focus keeps its workspace"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_workspaces_starts_from_the_monitor_under_the_pointer() {
|
||||
let (fake, mut wm) = pointer_on_the_empty_monitor();
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::FocusWorkspaceNumbers(1)).unwrap();
|
||||
|
||||
assert_eq!(wm.focused_monitor_idx(), 1);
|
||||
assert_eq!(wm.monitors()[0].focused_workspace_idx(), 1);
|
||||
assert_eq!(wm.monitors()[1].focused_workspace_idx(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn focus_last_workspace_acts_on_the_monitor_under_the_pointer() {
|
||||
let (fake, mut wm) = pointer_on_the_empty_monitor();
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::FocusLastWorkspace).unwrap();
|
||||
|
||||
assert_eq!(wm.focused_monitor_idx(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pointer_on_the_focused_monitor_changes_nothing() {
|
||||
let (fake, mut wm) = two_monitors();
|
||||
open_on_the_left(&fake, &mut wm, 33_002);
|
||||
fake.set_cursor(500, 300);
|
||||
|
||||
send(&fake, &mut wm, SocketMessage::FocusWorkspaceNumber(1)).unwrap();
|
||||
|
||||
assert_eq!(wm.focused_monitor_idx(), 0);
|
||||
assert_eq!(wm.monitors()[0].focused_workspace_idx(), 1);
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
//! [`Container`], the windows that share one tile of a workspace's layout.
|
||||
//!
|
||||
//! The container is [`komorebi_core::Container`], shared with the other komorebi daemons, over the
|
||||
//! macOS [`Window`]. What it cannot share is how a window is hidden: macOS needs the monitor's
|
||||
//! `WindowHidingPosition` (and for a whole container the bounds of its display) with every hide,
|
||||
//! and a hide can fail. Those four operations are [`ContainerExt`], under names the shared
|
||||
//! container does not use (`add_window_at`, `load_focused_window_at`, `hide_on`,
|
||||
//! `restore_focused_window`), because an inherent method of the shared type would hide an
|
||||
//! extension method of the same name.
|
||||
//! macOS [`Window`]. How a window is hidden is [`MacosHideSpot`]: the monitor's `WindowHidingPosition`
|
||||
//! and, for the containers of a workspace that is being hidden, the bounds of its display. The
|
||||
//! workspace gives it with `Workspace::hide_spot` and every container call takes it, as on the other
|
||||
//! platforms (where it is `()`).
|
||||
|
||||
use crate::accessibility::error::AccessibilityError;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::window::Window;
|
||||
use color_eyre::eyre;
|
||||
@@ -94,120 +91,6 @@ impl komorebi_core::WorkspaceWindow for Window {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a macOS container does that the shared one cannot: hide and restore its windows with the
|
||||
/// monitor's hiding position, and say when that failed.
|
||||
pub trait ContainerExt {
|
||||
/// Puts a window at the back of the container and gives it the front, hiding every other
|
||||
/// window of the container at `hiding_position`
|
||||
fn add_window_at(
|
||||
&mut self,
|
||||
window: &Window,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> eyre::Result<()>;
|
||||
|
||||
/// Hides the unfocused windows of the container and restores the focused one. This function
|
||||
/// is used to make sure we update the window that should be shown on a stack. If the container
|
||||
/// isn't a stack this function won't change anything.
|
||||
fn load_focused_window_at(
|
||||
&mut self,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> Result<(), AccessibilityError>;
|
||||
|
||||
/// Hide the windows of the container, other than `omit`, on `screen`, the bounds of the display
|
||||
/// of the monitor that has the container, or on whichever display they are found on if that is
|
||||
/// not given
|
||||
fn hide_on(
|
||||
&mut self,
|
||||
hiding_position: WindowHidingPosition,
|
||||
omit: Option<u32>,
|
||||
screen: Option<CGRect>,
|
||||
) -> eyre::Result<()>;
|
||||
|
||||
/// Restores the window in front, which is the one that is shown when the container is a stack
|
||||
fn restore_focused_window(&mut self) -> eyre::Result<()>;
|
||||
}
|
||||
|
||||
impl ContainerExt for Container {
|
||||
fn add_window_at(
|
||||
&mut self,
|
||||
window: &Window,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> eyre::Result<()> {
|
||||
self.windows_mut().push_back(window.clone());
|
||||
self.focus_window(self.windows().len().saturating_sub(1));
|
||||
|
||||
if !cfg!(test) {
|
||||
let focused_window_idx = self.focused_window_idx();
|
||||
|
||||
for (i, window) in self.windows_mut().iter_mut().enumerate() {
|
||||
if i != focused_window_idx {
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tracing::info!("not hiding windows to {hiding_position} during test execution")
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_focused_window_at(
|
||||
&mut self,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> Result<(), AccessibilityError> {
|
||||
let focused_idx = self.focused_window_idx();
|
||||
|
||||
if !cfg!(test) {
|
||||
for (i, window) in self.windows_mut().iter_mut().enumerate() {
|
||||
if i == focused_idx {
|
||||
window.restore()?;
|
||||
} else {
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tracing::info!(
|
||||
"not hiding/restoring windows to/from {hiding_position} during test execution"
|
||||
)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn hide_on(
|
||||
&mut self,
|
||||
hiding_position: WindowHidingPosition,
|
||||
omit: Option<u32>,
|
||||
screen: Option<CGRect>,
|
||||
) -> eyre::Result<()> {
|
||||
for window in self.windows_mut().iter_mut().rev() {
|
||||
let mut should_hide = omit.is_none();
|
||||
|
||||
if !should_hide
|
||||
&& let Some(omit) = omit
|
||||
&& omit != window.id
|
||||
{
|
||||
should_hide = true
|
||||
}
|
||||
|
||||
// a window that has gone away must not leave the ones after it in view
|
||||
if should_hide && let Err(error) = window.hide_on(hiding_position, screen) {
|
||||
tracing::warn!("failed to hide window {}: {error}", window.id);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn restore_focused_window(&mut self) -> eyre::Result<()> {
|
||||
if let Some(window) = self.focused_window_mut() {
|
||||
window.restore()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -220,7 +103,7 @@ mod tests {
|
||||
|
||||
for i in 0..3 {
|
||||
container
|
||||
.add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft)
|
||||
.add_window(Window::from(i), Default::default())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -239,7 +122,7 @@ mod tests {
|
||||
|
||||
for i in 0..3 {
|
||||
container
|
||||
.add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft)
|
||||
.add_window(Window::from(i), Default::default())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -259,7 +142,7 @@ mod tests {
|
||||
|
||||
for i in 0..3 {
|
||||
container
|
||||
.add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft)
|
||||
.add_window(Window::from(i), Default::default())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -281,7 +164,7 @@ mod tests {
|
||||
let mut container = Container::default();
|
||||
|
||||
container
|
||||
.add_window_at(&Window::from(1), WindowHidingPosition::BottomLeft)
|
||||
.add_window(Window::from(1), Default::default())
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(container.windows().len(), 1);
|
||||
@@ -295,7 +178,7 @@ mod tests {
|
||||
|
||||
for i in 0..3 {
|
||||
container
|
||||
.add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft)
|
||||
.add_window(Window::from(i), Default::default())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -321,7 +204,7 @@ mod tests {
|
||||
|
||||
for i in 0..3 {
|
||||
container
|
||||
.add_window_at(&Window::from(i), WindowHidingPosition::BottomLeft)
|
||||
.add_window(Window::from(i), Default::default())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
//! was), and what it does differently from the shared monitor is [`MonitorExt`].
|
||||
|
||||
use crate::container::Container;
|
||||
use crate::container::ContainerExt;
|
||||
use crate::core::DefaultLayout;
|
||||
use crate::core::Layout;
|
||||
use crate::core::OperationDirection;
|
||||
@@ -396,7 +395,7 @@ impl MonitorExt for Monitor {
|
||||
|
||||
if target_workspace.monocle_container.is_some() {
|
||||
for container in target_workspace.containers_mut() {
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
for window in target_workspace.floating_windows_mut() {
|
||||
@@ -454,7 +453,7 @@ impl MonitorExt for Monitor {
|
||||
|
||||
if target_workspace.monocle_container.is_some() {
|
||||
for container in target_workspace.containers_mut() {
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
target_workspace.reintegrate_monocle_container()?;
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::core::MonocleFocusBehaviour;
|
||||
use crate::core::MoveBehaviour;
|
||||
use crate::core::OperationDirection;
|
||||
use crate::core::Rect;
|
||||
use crate::core::Sizing;
|
||||
use crate::core::SocketMessage;
|
||||
use crate::core::StateQuery;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
@@ -592,37 +593,10 @@ impl WindowManager {
|
||||
}
|
||||
SocketMessage::FocusLastWorkspace => self.focus_last_workspace()?,
|
||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||
if self.focused_workspace_idx().unwrap_or_default() != workspace_idx {
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
}
|
||||
komorebi_core::focus_workspace_number(self, workspace_idx)?
|
||||
}
|
||||
SocketMessage::FocusWorkspaceNumbers(workspace_idx) => {
|
||||
// TODO: figure out if we need to do this on macOS
|
||||
// // This is to ensure that even on an empty workspace on a secondary monitor, the
|
||||
// // secondary monitor where the cursor is focused will be used as the target for
|
||||
// // the workspace switch op
|
||||
// if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
|
||||
// if monitor_idx != self.focused_monitor_idx() {
|
||||
// if let Some(monitor) = self.monitors().get(monitor_idx) {
|
||||
// if let Some(workspace) = monitor.focused_workspace() {
|
||||
// if workspace.is_empty() {
|
||||
// self.focus_monitor(monitor_idx)?;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
|
||||
for (i, monitor) in self.monitors_mut().iter_mut().enumerate() {
|
||||
if i != focused_monitor_idx {
|
||||
monitor.focus_workspace(workspace_idx)?;
|
||||
monitor.load_focused_workspace(false)?;
|
||||
}
|
||||
}
|
||||
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
komorebi_core::focus_workspace_numbers(self, workspace_idx)?
|
||||
}
|
||||
SocketMessage::FocusMonitorWorkspaceNumber(monitor_idx, workspace_idx) => {
|
||||
komorebi_core::focus_monitor_workspace_number(self, monitor_idx, workspace_idx)?
|
||||
@@ -645,117 +619,7 @@ impl WindowManager {
|
||||
}
|
||||
SocketMessage::ToggleMonocle => self.toggle_monocle()?,
|
||||
SocketMessage::ToggleFloat => self.toggle_float(false)?,
|
||||
SocketMessage::ToggleWorkspaceLayer => {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let hiding_position = self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.extra
|
||||
.window_hiding_position;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let mut to_focus = None;
|
||||
match workspace.layer {
|
||||
WorkspaceLayer::Tiling => {
|
||||
workspace.layer = WorkspaceLayer::Floating;
|
||||
tracing::info!("WorkspaceLayer is now Floating");
|
||||
|
||||
let focused_idx = workspace.focused_floating_window_idx();
|
||||
let mut window_idx_pairs = workspace
|
||||
.floating_windows_mut()
|
||||
.make_contiguous()
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Sort by window area
|
||||
window_idx_pairs.sort_by_key(|(_, w)| {
|
||||
let rect = Rect::from(w.window_rect().unwrap_or_default());
|
||||
rect.right * rect.bottom
|
||||
});
|
||||
window_idx_pairs.reverse();
|
||||
|
||||
for (i, window) in window_idx_pairs {
|
||||
if i == focused_idx {
|
||||
to_focus = Some(window.clone());
|
||||
} else {
|
||||
window.restore()?;
|
||||
window.raise()?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(focused_window) = &mut to_focus {
|
||||
// The focused window should be the last one raised to make sure it is
|
||||
// on top
|
||||
focused_window.restore()?;
|
||||
focused_window.raise()?;
|
||||
}
|
||||
|
||||
for container in workspace.containers() {
|
||||
if let Some(_window) = container.focused_window() {
|
||||
// TODO: figure out z order
|
||||
// window.lower()?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(monocle) = &workspace.monocle_container
|
||||
&& let Some(_window) = monocle.focused_window()
|
||||
{
|
||||
// TODO: figure out z order
|
||||
// window.lower()?;
|
||||
}
|
||||
}
|
||||
WorkspaceLayer::Floating => {
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
tracing::info!("WorkspaceLayer is now Tiling");
|
||||
|
||||
if let Some(monocle) = &workspace.monocle_container {
|
||||
if let Some(window) = monocle.focused_window() {
|
||||
to_focus = Some(window.clone());
|
||||
window.raise()?;
|
||||
}
|
||||
|
||||
for window in workspace.floating_windows_mut() {
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
} else {
|
||||
let focused_container_idx = workspace.focused_container_idx();
|
||||
for (i, container) in workspace.containers_mut().iter_mut().enumerate()
|
||||
{
|
||||
if let Some(window) = container.focused_window() {
|
||||
if i == focused_container_idx {
|
||||
to_focus = Some(window.clone());
|
||||
}
|
||||
|
||||
window.raise()?;
|
||||
}
|
||||
}
|
||||
|
||||
let mut window_idx_pairs = workspace
|
||||
.floating_windows_mut()
|
||||
.make_contiguous()
|
||||
.iter_mut()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Sort by window area
|
||||
window_idx_pairs.sort_by_key(|w| {
|
||||
let rect = Rect::from(w.window_rect().unwrap_or_default());
|
||||
rect.right * rect.bottom
|
||||
});
|
||||
|
||||
for window in window_idx_pairs {
|
||||
// TODO: figure out z order
|
||||
window.hide(hiding_position)?;
|
||||
// window.lower()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(window) = to_focus {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
}
|
||||
SocketMessage::ToggleWorkspaceLayer => self.toggle_workspace_layer()?,
|
||||
SocketMessage::ResizeWindowEdge(direction, sizing) => {
|
||||
// resizing is done by the key, over and over, and every press is laid out where it
|
||||
// goes and not by an animation that the next press would have to catch up with
|
||||
@@ -763,65 +627,7 @@ impl WindowManager {
|
||||
self.resize_window(direction, sizing, self.resize_delta, true)?;
|
||||
}
|
||||
SocketMessage::ResizeWindowAxis(axis, sizing) => {
|
||||
let _suspended_animations = animation::suspend();
|
||||
match axis {
|
||||
Axis::Horizontal => {
|
||||
self.resize_window(
|
||||
OperationDirection::Left,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
self.resize_window(
|
||||
OperationDirection::Right,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
}
|
||||
Axis::Vertical => {
|
||||
self.resize_window(
|
||||
OperationDirection::Up,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
self.resize_window(
|
||||
OperationDirection::Down,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
}
|
||||
Axis::HorizontalAndVertical => {
|
||||
self.resize_window(
|
||||
OperationDirection::Left,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
self.resize_window(
|
||||
OperationDirection::Right,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
self.resize_window(
|
||||
OperationDirection::Up,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
self.resize_window(
|
||||
OperationDirection::Down,
|
||||
sizing,
|
||||
self.resize_delta,
|
||||
false,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
self.update_focused_workspace(false, false)?;
|
||||
self.resize_window_axis(axis, sizing)?
|
||||
}
|
||||
SocketMessage::Retile => self.retile_all(false)?,
|
||||
SocketMessage::RetileWithResizeDimensions => self.retile_all(true)?,
|
||||
@@ -1012,42 +818,7 @@ impl WindowManager {
|
||||
reply.write_all(monitors_state.as_bytes())?;
|
||||
}
|
||||
SocketMessage::Query(query) => self.answer_query(query, &mut reply)?,
|
||||
SocketMessage::SessionFloatRule => {
|
||||
let foreground_window =
|
||||
MacosApi::foreground_window().ok_or_eyre("there is no foreground window")?;
|
||||
let (exe, title, role) = (
|
||||
AdhocWindow::exe(&foreground_window),
|
||||
AdhocWindow::title(&foreground_window),
|
||||
AdhocWindow::role(&foreground_window),
|
||||
);
|
||||
|
||||
if let (Some(exe), Some(title), Some(role)) = (exe, title, role) {
|
||||
let rule = MatchingRule::Composite(vec![
|
||||
IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Exe,
|
||||
id: exe,
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
},
|
||||
IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Title,
|
||||
id: title,
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
},
|
||||
IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Class,
|
||||
id: role,
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
},
|
||||
]);
|
||||
|
||||
let mut floating_applications = FLOATING_APPLICATIONS.lock();
|
||||
floating_applications.push(rule.clone());
|
||||
let mut session_floating_applications = SESSION_FLOATING_APPLICATIONS.lock();
|
||||
session_floating_applications.push(rule.clone());
|
||||
|
||||
self.toggle_float(true)?;
|
||||
}
|
||||
}
|
||||
SocketMessage::SessionFloatRule => self.add_session_float_rule()?,
|
||||
SocketMessage::SessionFloatRules => {
|
||||
let session_floating_applications = SESSION_FLOATING_APPLICATIONS.lock();
|
||||
let rules = serde_json::to_string_pretty(&*session_floating_applications)
|
||||
@@ -1130,78 +901,7 @@ impl WindowManager {
|
||||
self.enforce_workspace_rules()?;
|
||||
}
|
||||
SocketMessage::IgnoreRule(identifier, ref id) => {
|
||||
let mut ignore_identifiers = IGNORE_IDENTIFIERS.lock();
|
||||
|
||||
let mut should_push = true;
|
||||
for i in &*ignore_identifiers {
|
||||
if let MatchingRule::Simple(i) = i
|
||||
&& i.id.eq(id)
|
||||
{
|
||||
should_push = false;
|
||||
}
|
||||
}
|
||||
|
||||
if should_push {
|
||||
ignore_identifiers.push(MatchingRule::Simple(IdWithIdentifier {
|
||||
kind: identifier,
|
||||
id: id.clone(),
|
||||
matching_strategy: Option::from(MatchingStrategy::Legacy),
|
||||
}));
|
||||
}
|
||||
|
||||
let offset = self.work_area_offset;
|
||||
|
||||
let mut window_ids_to_purge = vec![];
|
||||
for (i, monitor) in self.monitors().iter().enumerate() {
|
||||
for container in monitor
|
||||
.focused_workspace()
|
||||
.ok_or_eyre("there is no workspace")?
|
||||
.containers()
|
||||
{
|
||||
for window in container.windows() {
|
||||
match identifier {
|
||||
ApplicationIdentifier::Path => {
|
||||
if window.path().unwrap_or_default().to_string_lossy() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
ApplicationIdentifier::Exe => {
|
||||
if window.exe().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
ApplicationIdentifier::Class => {
|
||||
if window.role().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
|
||||
if window.subrole().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
ApplicationIdentifier::Title => {
|
||||
if window.title().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (monitor_idx, id) in window_ids_to_purge {
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
.ok_or_eyre("there is no monitor")?;
|
||||
|
||||
monitor
|
||||
.focused_workspace_mut()
|
||||
.ok_or_eyre("there is no focused workspace")?
|
||||
.remove_window(id)?;
|
||||
|
||||
monitor.update_focused_workspace(offset)?;
|
||||
}
|
||||
self.add_ignore_rule(identifier, id)?
|
||||
}
|
||||
SocketMessage::ManageRule(identifier, ref id) => {
|
||||
let mut manage_identifiers = MANAGE_IDENTIFIERS.lock();
|
||||
@@ -1562,34 +1262,7 @@ impl WindowManager {
|
||||
});
|
||||
}
|
||||
SocketMessage::ReplaceConfiguration(ref config) => {
|
||||
// Check that this is a valid static config file first
|
||||
if StaticConfig::read(config).is_ok() {
|
||||
// Clear workspace rules; these will need to be replaced
|
||||
WORKSPACE_MATCHING_RULES.lock().clear();
|
||||
// Pause so that restored windows come to the foreground from all workspaces
|
||||
self.is_paused = true;
|
||||
// Bring all windows to the foreground
|
||||
self.restore_all_windows(false)?;
|
||||
|
||||
// Create a new wm from the config path
|
||||
let mut wm = StaticConfig::preload(
|
||||
config,
|
||||
window_manager_event_listener::event_rx(),
|
||||
self.command_listener.try_clone().ok(),
|
||||
&self.run_loop.0,
|
||||
)?;
|
||||
|
||||
// Initialize the new wm
|
||||
wm.init()?;
|
||||
|
||||
wm.restore_all_windows(true)?;
|
||||
|
||||
// This is equivalent to StaticConfig::postload for this use case
|
||||
StaticConfig::reload(config, &mut wm)?;
|
||||
|
||||
// Set self to the new wm instance
|
||||
*self = wm;
|
||||
}
|
||||
self.replace_configuration(config)?
|
||||
}
|
||||
SocketMessage::Border(enable) => {
|
||||
border_manager::BORDER_ENABLED.store(enable, Ordering::SeqCst);
|
||||
@@ -1727,6 +1400,298 @@ pub fn read_commands_uds(wm: &Arc<Mutex<WindowManager>>, stream: UnixStream) ->
|
||||
komorebi_transport::read_commands::<WindowManager, _>(wm, stream, &NoPolicy)
|
||||
}
|
||||
|
||||
impl WindowManager {
|
||||
/// Switches the focused workspace between its tiling and floating layers, and focuses a window of the layer it switched to
|
||||
pub fn toggle_workspace_layer(&mut self) -> eyre::Result<()> {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let hiding_position = self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.extra
|
||||
.window_hiding_position;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let mut to_focus = None;
|
||||
match workspace.layer {
|
||||
WorkspaceLayer::Tiling => {
|
||||
workspace.layer = WorkspaceLayer::Floating;
|
||||
tracing::info!("WorkspaceLayer is now Floating");
|
||||
|
||||
let focused_idx = workspace.focused_floating_window_idx();
|
||||
let mut window_idx_pairs = workspace
|
||||
.floating_windows_mut()
|
||||
.make_contiguous()
|
||||
.iter_mut()
|
||||
.enumerate()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Sort by window area
|
||||
window_idx_pairs.sort_by_key(|(_, w)| {
|
||||
let rect = Rect::from(w.window_rect().unwrap_or_default());
|
||||
rect.right * rect.bottom
|
||||
});
|
||||
window_idx_pairs.reverse();
|
||||
|
||||
for (i, window) in window_idx_pairs {
|
||||
if i == focused_idx {
|
||||
to_focus = Some(window.clone());
|
||||
} else {
|
||||
window.restore()?;
|
||||
window.raise()?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(focused_window) = &mut to_focus {
|
||||
// The focused window should be the last one raised to make sure it is
|
||||
// on top
|
||||
focused_window.restore()?;
|
||||
focused_window.raise()?;
|
||||
}
|
||||
|
||||
for container in workspace.containers() {
|
||||
if let Some(_window) = container.focused_window() {
|
||||
// TODO: figure out z order
|
||||
// window.lower()?;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(monocle) = &workspace.monocle_container
|
||||
&& let Some(_window) = monocle.focused_window()
|
||||
{
|
||||
// TODO: figure out z order
|
||||
// window.lower()?;
|
||||
}
|
||||
}
|
||||
WorkspaceLayer::Floating => {
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
tracing::info!("WorkspaceLayer is now Tiling");
|
||||
|
||||
if let Some(monocle) = &workspace.monocle_container {
|
||||
if let Some(window) = monocle.focused_window() {
|
||||
to_focus = Some(window.clone());
|
||||
window.raise()?;
|
||||
}
|
||||
|
||||
for window in workspace.floating_windows_mut() {
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
} else {
|
||||
let focused_container_idx = workspace.focused_container_idx();
|
||||
for (i, container) in workspace.containers_mut().iter_mut().enumerate() {
|
||||
if let Some(window) = container.focused_window() {
|
||||
if i == focused_container_idx {
|
||||
to_focus = Some(window.clone());
|
||||
}
|
||||
|
||||
window.raise()?;
|
||||
}
|
||||
}
|
||||
|
||||
let mut window_idx_pairs = workspace
|
||||
.floating_windows_mut()
|
||||
.make_contiguous()
|
||||
.iter_mut()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Sort by window area
|
||||
window_idx_pairs.sort_by_key(|w| {
|
||||
let rect = Rect::from(w.window_rect().unwrap_or_default());
|
||||
rect.right * rect.bottom
|
||||
});
|
||||
|
||||
for window in window_idx_pairs {
|
||||
// TODO: figure out z order
|
||||
window.hide(hiding_position)?;
|
||||
// window.lower()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(window) = to_focus {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Resizes the focused window along an axis, by the edge that the axis says
|
||||
pub fn resize_window_axis(&mut self, axis: Axis, sizing: Sizing) -> eyre::Result<()> {
|
||||
let _suspended_animations = animation::suspend();
|
||||
match axis {
|
||||
Axis::Horizontal => {
|
||||
self.resize_window(OperationDirection::Left, sizing, self.resize_delta, false)?;
|
||||
self.resize_window(OperationDirection::Right, sizing, self.resize_delta, false)?;
|
||||
}
|
||||
Axis::Vertical => {
|
||||
self.resize_window(OperationDirection::Up, sizing, self.resize_delta, false)?;
|
||||
self.resize_window(OperationDirection::Down, sizing, self.resize_delta, false)?;
|
||||
}
|
||||
Axis::HorizontalAndVertical => {
|
||||
self.resize_window(OperationDirection::Left, sizing, self.resize_delta, false)?;
|
||||
self.resize_window(OperationDirection::Right, sizing, self.resize_delta, false)?;
|
||||
self.resize_window(OperationDirection::Up, sizing, self.resize_delta, false)?;
|
||||
self.resize_window(OperationDirection::Down, sizing, self.resize_delta, false)?;
|
||||
}
|
||||
}
|
||||
|
||||
self.update_focused_workspace(false, false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Adds a float rule for the focused window (its executable, title and role), until the daemon stops
|
||||
pub fn add_session_float_rule(&mut self) -> eyre::Result<()> {
|
||||
let foreground_window =
|
||||
MacosApi::foreground_window().ok_or_eyre("there is no foreground window")?;
|
||||
let (exe, title, role) = (
|
||||
AdhocWindow::exe(&foreground_window),
|
||||
AdhocWindow::title(&foreground_window),
|
||||
AdhocWindow::role(&foreground_window),
|
||||
);
|
||||
|
||||
if let (Some(exe), Some(title), Some(role)) = (exe, title, role) {
|
||||
let rule = MatchingRule::Composite(vec![
|
||||
IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Exe,
|
||||
id: exe,
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
},
|
||||
IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Title,
|
||||
id: title,
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
},
|
||||
IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Class,
|
||||
id: role,
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
},
|
||||
]);
|
||||
|
||||
let mut floating_applications = FLOATING_APPLICATIONS.lock();
|
||||
floating_applications.push(rule.clone());
|
||||
let mut session_floating_applications = SESSION_FLOATING_APPLICATIONS.lock();
|
||||
session_floating_applications.push(rule.clone());
|
||||
|
||||
self.toggle_float(true)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Adds a rule that ignores the windows matching `id`, and takes the ones it matches out of the workspaces
|
||||
pub fn add_ignore_rule(
|
||||
&mut self,
|
||||
identifier: ApplicationIdentifier,
|
||||
id: &str,
|
||||
) -> eyre::Result<()> {
|
||||
let mut ignore_identifiers = IGNORE_IDENTIFIERS.lock();
|
||||
|
||||
let mut should_push = true;
|
||||
for i in &*ignore_identifiers {
|
||||
if let MatchingRule::Simple(i) = i
|
||||
&& i.id == id
|
||||
{
|
||||
should_push = false;
|
||||
}
|
||||
}
|
||||
|
||||
if should_push {
|
||||
ignore_identifiers.push(MatchingRule::Simple(IdWithIdentifier {
|
||||
kind: identifier,
|
||||
id: id.to_string(),
|
||||
matching_strategy: Option::from(MatchingStrategy::Legacy),
|
||||
}));
|
||||
}
|
||||
|
||||
let offset = self.work_area_offset;
|
||||
|
||||
let mut window_ids_to_purge = vec![];
|
||||
for (i, monitor) in self.monitors().iter().enumerate() {
|
||||
for container in monitor
|
||||
.focused_workspace()
|
||||
.ok_or_eyre("there is no workspace")?
|
||||
.containers()
|
||||
{
|
||||
for window in container.windows() {
|
||||
match identifier {
|
||||
ApplicationIdentifier::Path => {
|
||||
if window.path().unwrap_or_default().to_string_lossy() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
ApplicationIdentifier::Exe => {
|
||||
if window.exe().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
ApplicationIdentifier::Class => {
|
||||
if window.role().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
|
||||
if window.subrole().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
ApplicationIdentifier::Title => {
|
||||
if window.title().unwrap_or_default() == *id {
|
||||
window_ids_to_purge.push((i, window.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (monitor_idx, id) in window_ids_to_purge {
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
.ok_or_eyre("there is no monitor")?;
|
||||
|
||||
monitor
|
||||
.focused_workspace_mut()
|
||||
.ok_or_eyre("there is no focused workspace")?
|
||||
.remove_window(id)?;
|
||||
|
||||
monitor.update_focused_workspace(offset)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Replaces the running configuration with the one in the file
|
||||
pub fn replace_configuration(&mut self, config: &std::path::Path) -> eyre::Result<()> {
|
||||
// Check that this is a valid static config file first
|
||||
if StaticConfig::read(config).is_ok() {
|
||||
// Clear workspace rules; these will need to be replaced
|
||||
WORKSPACE_MATCHING_RULES.lock().clear();
|
||||
// Pause so that restored windows come to the foreground from all workspaces
|
||||
self.is_paused = true;
|
||||
// Bring all windows to the foreground
|
||||
self.restore_all_windows(false)?;
|
||||
|
||||
// Create a new wm from the config path
|
||||
let mut wm = StaticConfig::preload(
|
||||
config,
|
||||
window_manager_event_listener::event_rx(),
|
||||
self.command_listener.try_clone().ok(),
|
||||
&self.run_loop.0,
|
||||
)?;
|
||||
|
||||
// Initialize the new wm
|
||||
wm.init()?;
|
||||
|
||||
wm.restore_all_windows(true)?;
|
||||
|
||||
// This is equivalent to StaticConfig::postload for this use case
|
||||
StaticConfig::reload(config, &mut wm)?;
|
||||
|
||||
// Set self to the new wm instance
|
||||
*self = wm;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// The window manager as the shared commands of `komorebi_core::command` see it
|
||||
impl komorebi_core::CommandHost for WindowManager {
|
||||
type P = crate::workspace::MacosPlatform;
|
||||
@@ -1759,6 +1724,16 @@ impl komorebi_core::CommandHost for WindowManager {
|
||||
WindowManager::focus_workspace(self, idx)
|
||||
}
|
||||
|
||||
fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()> {
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
.ok_or_eyre("there is no monitor at this index")?;
|
||||
monitor.focus_workspace(workspace_idx)?;
|
||||
monitor.load_focused_workspace(false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn move_container_to_workspace(
|
||||
&mut self,
|
||||
idx: usize,
|
||||
|
||||
@@ -13,7 +13,6 @@ use crate::accessibility::notification_constants::AccessibilityNotification;
|
||||
use crate::animation::animator;
|
||||
use crate::app_kit_notification_constants::AppKitWorkspaceNotification;
|
||||
use crate::border_manager;
|
||||
use crate::container::ContainerExt;
|
||||
use crate::core::DefaultLayout;
|
||||
use crate::core::Layout;
|
||||
use crate::core::Rect;
|
||||
@@ -701,11 +700,11 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
WindowContainerBehaviour::Append => {
|
||||
let window_hiding_position = workspace.state.window_hiding_position;
|
||||
let spot = workspace.hide_spot();
|
||||
workspace
|
||||
.focused_container_mut()
|
||||
.ok_or_eyre("there is no focused container")?
|
||||
.add_window_at(&window, window_hiding_position)?;
|
||||
.add_window(window.clone(), spot)?;
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
self.update_focused_workspace(true, false)?;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
use crate::arrival;
|
||||
use crate::container::Container;
|
||||
use crate::container::ContainerExt;
|
||||
use crate::core::LayoutOptions;
|
||||
use crate::core::OperationDirection;
|
||||
use crate::core::Rect;
|
||||
@@ -60,7 +59,7 @@ fn show(container: &mut Container) -> eyre::Result<()> {
|
||||
});
|
||||
|
||||
#[cfg(not(test))]
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -632,7 +631,7 @@ impl WorkspaceScrolling for Workspace {
|
||||
}
|
||||
|
||||
fn stack_scrolling_column(&mut self, column: &[String]) -> eyre::Result<()> {
|
||||
let hiding_position = self.state.window_hiding_position;
|
||||
let spot = self.hide_spot();
|
||||
|
||||
let focused_window = self
|
||||
.focused_container()
|
||||
@@ -654,7 +653,7 @@ impl WorkspaceScrolling for Workspace {
|
||||
|
||||
if let Some(container) = self.containers_mut().get_mut(idx) {
|
||||
for window in &windows {
|
||||
container.add_window_at(window, hiding_position)?;
|
||||
container.add_window(window.clone(), spot)?;
|
||||
}
|
||||
|
||||
// the window that had focus is the one that is showing
|
||||
@@ -665,7 +664,7 @@ impl WorkspaceScrolling for Workspace {
|
||||
}
|
||||
|
||||
if !cfg!(test) {
|
||||
container.load_focused_window_at(hiding_position)?;
|
||||
container.load_focused_window(spot)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,7 +674,7 @@ impl WorkspaceScrolling for Workspace {
|
||||
}
|
||||
|
||||
fn unstack_scrolling_column(&mut self) -> eyre::Result<bool> {
|
||||
let hiding_position = self.state.window_hiding_position;
|
||||
let spot = self.hide_spot();
|
||||
let idx = self.focused_container_idx();
|
||||
|
||||
let Some(container) = self.containers_mut().get_mut(idx) else {
|
||||
@@ -703,7 +702,7 @@ impl WorkspaceScrolling for Workspace {
|
||||
let mut ids = vec![];
|
||||
for (offset, window) in rest.iter().enumerate() {
|
||||
let mut container = Container::default();
|
||||
container.add_window_at(window, hiding_position)?;
|
||||
container.add_window(window.clone(), spot)?;
|
||||
ids.push(container.id.clone());
|
||||
|
||||
// it was one of the tabs that were out of sight, and has to be put where it is shown
|
||||
@@ -1448,7 +1447,7 @@ mod tests {
|
||||
.containers_mut()
|
||||
.front_mut()
|
||||
.unwrap()
|
||||
.add_window_at(&Window::from(6_000_062), WindowHidingPosition::default())
|
||||
.add_window(Window::from(6_000_062), Default::default())
|
||||
.unwrap();
|
||||
workspace.layout_scrolling(&AREA, 0);
|
||||
|
||||
@@ -1839,7 +1838,7 @@ mod tests {
|
||||
.containers_mut()
|
||||
.front_mut()
|
||||
.unwrap()
|
||||
.add_window_at(&Window::from(212), WindowHidingPosition::default())
|
||||
.add_window(Window::from(212), Default::default())
|
||||
.unwrap();
|
||||
workspace.layout_scrolling(&AREA, 0);
|
||||
assert_eq!(windows_of(&workspace), [vec![210, 212], vec![211]]);
|
||||
|
||||
@@ -17,7 +17,6 @@ use crate::application::Application;
|
||||
use crate::border_manager;
|
||||
use crate::border_manager::BorderLook;
|
||||
use crate::container::Container;
|
||||
use crate::container::ContainerExt;
|
||||
use crate::core::Arrangement;
|
||||
use crate::core::Axis;
|
||||
use crate::core::CrossBoundaryBehaviour;
|
||||
@@ -1249,9 +1248,9 @@ impl WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
let window_hiding_position = workspace.state.window_hiding_position;
|
||||
let spot = workspace.hide_spot();
|
||||
if changed_focus && let Some(container) = workspace.focused_container_mut() {
|
||||
container.load_focused_window_at(window_hiding_position)?;
|
||||
container.load_focused_window(spot)?;
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
@@ -1332,7 +1331,7 @@ impl WindowManager {
|
||||
tracing::info!("cycling container windows");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let window_hiding_position = self.focused_workspace()?.state.window_hiding_position;
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
|
||||
let container = self.focused_container_mut()?;
|
||||
|
||||
@@ -1347,7 +1346,7 @@ impl WindowManager {
|
||||
let next_idx = direction.next_idx(current_idx, len);
|
||||
|
||||
container.focus_window(next_idx);
|
||||
container.load_focused_window_at(window_hiding_position)?;
|
||||
container.load_focused_window(spot)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -1545,17 +1544,12 @@ impl WindowManager {
|
||||
pub fn monocle_on(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("enabling monocle");
|
||||
|
||||
let hiding_position = self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.extra
|
||||
.window_hiding_position;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.new_monocle_container()?;
|
||||
|
||||
let spot = workspace.hide_spot();
|
||||
for container in workspace.containers_mut() {
|
||||
container.hide_on(hiding_position, None, None)?;
|
||||
container.hide(None, spot)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -1568,7 +1562,7 @@ impl WindowManager {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
for container in workspace.containers_mut() {
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
workspace.reintegrate_monocle_container()
|
||||
@@ -1582,17 +1576,12 @@ impl WindowManager {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let hiding_position = self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.extra
|
||||
.window_hiding_position;
|
||||
|
||||
self.focused_workspace_mut()?
|
||||
.cycle_monocle_container(direction)?;
|
||||
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
for container in self.focused_workspace_mut()?.containers_mut() {
|
||||
container.hide_on(hiding_position, None, None)?;
|
||||
container.hide(None, spot)?;
|
||||
}
|
||||
|
||||
self.update_focused_workspace(true, true)
|
||||
@@ -2611,7 +2600,7 @@ impl WindowManager {
|
||||
|
||||
if target_workspace.monocle_container.is_some() {
|
||||
for container in target_workspace.containers_mut() {
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
for window in target_workspace.floating_windows_mut() {
|
||||
@@ -2881,7 +2870,7 @@ impl WindowManager {
|
||||
tracing::info!("cycling container window index");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let window_hiding_position = self.focused_workspace()?.state.window_hiding_position;
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
@@ -2902,7 +2891,7 @@ impl WindowManager {
|
||||
container.windows_mut().swap(current_idx, next_idx);
|
||||
|
||||
container.focus_window(next_idx);
|
||||
container.load_focused_window_at(window_hiding_position)?;
|
||||
container.load_focused_window(spot)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -2916,7 +2905,7 @@ impl WindowManager {
|
||||
tracing::info!("focusing container window at index {idx}");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let window_hiding_position = self.focused_workspace()?.state.window_hiding_position;
|
||||
let spot = self.focused_workspace()?.hide_spot();
|
||||
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
@@ -2937,7 +2926,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
container.focus_window(idx);
|
||||
container.load_focused_window_at(window_hiding_position)?;
|
||||
container.load_focused_window(spot)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -2951,7 +2940,7 @@ impl WindowManager {
|
||||
tracing::info!("stacking all windows on workspace");
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let window_hiding_position = workspace.state.window_hiding_position;
|
||||
let spot = workspace.hide_spot();
|
||||
|
||||
let mut focused_hwnd = None;
|
||||
if let Some(container) = workspace.focused_container()
|
||||
@@ -2979,7 +2968,7 @@ impl WindowManager {
|
||||
&& let Some(w_idx_to_focus) = c.idx_for_window(hwnd)
|
||||
{
|
||||
c.focus_window(w_idx_to_focus);
|
||||
c.load_focused_window_at(window_hiding_position)?;
|
||||
c.load_focused_window(spot)?;
|
||||
}
|
||||
self.update_focused_workspace(self.mouse_follows_focus, true)
|
||||
}
|
||||
@@ -3783,7 +3772,7 @@ impl WindowManager {
|
||||
.ok_or_eyre("there is no workspace for this monitor")?;
|
||||
|
||||
for container in origin_workspace.containers_mut() {
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
origin_workspace.reintegrate_monocle_container()?;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
use crate::DATA_DIR;
|
||||
use crate::REGEX_IDENTIFIERS;
|
||||
use crate::container::ContainerExt;
|
||||
use crate::container::MacosHideSpot;
|
||||
use crate::core::DefaultLayout;
|
||||
use crate::core::Layout;
|
||||
@@ -464,7 +463,7 @@ impl WorkspaceExt for Workspace {
|
||||
}
|
||||
|
||||
for c in self.containers_mut() {
|
||||
c.restore_focused_window()?;
|
||||
c.restore()?;
|
||||
}
|
||||
|
||||
return Ok(window);
|
||||
@@ -474,7 +473,7 @@ impl WorkspaceExt for Workspace {
|
||||
.container_idx_for_window(window_id)
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
let window_hiding_position = self.state.window_hiding_position;
|
||||
let spot = self.hide_spot();
|
||||
|
||||
// a strip of columns has to know what there is before it is told what goes
|
||||
self.sync_scrolling_containers();
|
||||
@@ -502,7 +501,7 @@ impl WorkspaceExt for Workspace {
|
||||
self.focus_previous_container();
|
||||
}
|
||||
} else {
|
||||
container.load_focused_window_at(window_hiding_position)?;
|
||||
container.load_focused_window(spot)?;
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(false)?;
|
||||
}
|
||||
@@ -523,7 +522,7 @@ impl WorkspaceExt for Workspace {
|
||||
|
||||
fn restore_windows(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> {
|
||||
if let Some(container) = &mut self.monocle_container {
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -544,7 +543,7 @@ impl WorkspaceExt for Workspace {
|
||||
}
|
||||
|
||||
for container in self.containers_mut() {
|
||||
container.restore_focused_window()?;
|
||||
container.restore()?;
|
||||
}
|
||||
|
||||
if let Some(container) = self.focused_container_mut() {
|
||||
@@ -1074,7 +1073,7 @@ mod tests {
|
||||
let window = ws.floating_windows_mut().pop_back().unwrap();
|
||||
let mut container = Container::default();
|
||||
container
|
||||
.add_window_at(&window, WindowHidingPosition::BottomLeft)
|
||||
.add_window(window, Default::default())
|
||||
.unwrap();
|
||||
ws.insert_container_at_idx(ws.focused_container_idx(), container);
|
||||
|
||||
|
||||
@@ -927,21 +927,7 @@ impl WindowManager {
|
||||
self.focus_last_workspace()?;
|
||||
}
|
||||
SocketMessage::FocusWorkspaceNumber(workspace_idx) => {
|
||||
// This is to ensure that even on an empty workspace on a secondary monitor, the
|
||||
// secondary monitor where the cursor is focused will be used as the target for
|
||||
// the workspace switch op
|
||||
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
|
||||
&& monitor_idx != self.focused_monitor_idx()
|
||||
&& let Some(monitor) = self.monitors().get(monitor_idx)
|
||||
&& let Some(workspace) = monitor.focused_workspace()
|
||||
&& workspace.is_empty()
|
||||
{
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
}
|
||||
|
||||
if self.focused_workspace_idx().unwrap_or_default() != workspace_idx {
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
}
|
||||
komorebi_core::focus_workspace_number(self, workspace_idx)?
|
||||
}
|
||||
SocketMessage::FocusWorkspaceNumbers(workspace_idx) => {
|
||||
self.focus_workspace_numbers(workspace_idx)?;
|
||||
@@ -2145,29 +2131,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
pub fn focus_workspace_numbers(&mut self, workspace_idx: usize) -> eyre::Result<()> {
|
||||
// This is to ensure that even on an empty workspace on a secondary monitor, the
|
||||
// secondary monitor where the cursor is focused will be used as the target for
|
||||
// the workspace switch op
|
||||
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
|
||||
&& monitor_idx != self.focused_monitor_idx()
|
||||
&& let Some(monitor) = self.monitors().get(monitor_idx)
|
||||
&& let Some(workspace) = monitor.focused_workspace()
|
||||
&& workspace.is_empty()
|
||||
{
|
||||
self.focus_monitor(monitor_idx)?;
|
||||
}
|
||||
|
||||
let focused_monitor_idx = self.focused_monitor_idx();
|
||||
|
||||
for (i, monitor) in self.monitors_mut().iter_mut().enumerate() {
|
||||
if i != focused_monitor_idx {
|
||||
monitor.focus_workspace(workspace_idx)?;
|
||||
monitor.load_focused_workspace(false)?;
|
||||
}
|
||||
}
|
||||
|
||||
self.focus_workspace(workspace_idx)?;
|
||||
Ok(())
|
||||
komorebi_core::focus_workspace_numbers(self, workspace_idx)
|
||||
}
|
||||
|
||||
pub fn focus_last_workspace(&mut self) -> eyre::Result<()> {
|
||||
@@ -2293,9 +2257,6 @@ impl WindowManager {
|
||||
impl komorebi_core::CommandHost for WindowManager {
|
||||
type P = crate::workspace::WindowsPlatform;
|
||||
|
||||
// Windows lets the pointer pick the monitor first for these commands too
|
||||
const POINTER_PICKS_THE_MONITOR_FOR_ALL: bool = true;
|
||||
|
||||
fn monitors(&self) -> &std::collections::VecDeque<crate::monitor::Monitor> {
|
||||
WindowManager::monitors(self)
|
||||
}
|
||||
@@ -2324,6 +2285,16 @@ impl komorebi_core::CommandHost for WindowManager {
|
||||
WindowManager::focus_workspace(self, idx)
|
||||
}
|
||||
|
||||
fn show_workspace_on(&mut self, monitor_idx: usize, workspace_idx: usize) -> eyre::Result<()> {
|
||||
let monitor = self
|
||||
.monitors_mut()
|
||||
.get_mut(monitor_idx)
|
||||
.ok_or_eyre("there is no monitor at this index")?;
|
||||
monitor.focus_workspace(workspace_idx)?;
|
||||
monitor.load_focused_workspace(false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn move_container_to_workspace(
|
||||
&mut self,
|
||||
idx: usize,
|
||||
|
||||
Reference in new issue
Block a user