mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 22:33:12 +01:00
feat(kwin): easing curves for animations
An animation that moves a window at one pace all the way looks flat, and the stock Geometry Change has one curve, an exponential ease out. The patched effect reads a Curve setting, the name of one of Qt's easing curves. komorebi's styles are those curves with Ease in front, so the look the backend is asked for names the curve as Qt does, and the effect's settings have it next to the duration. A cubic Bezier, which only a configuration can say, is not one of Qt's curves and is an ease out. With the stock effect every style is that ease out. komorebic gets animation-style, for every animation or the movement of windows alone. vm-features puts two curves a few seconds into a 30 s move of the same window and checks that they are in different places. The animation key of komorebi.json takes a style too, for every kind of animation or for one.
This commit is contained in:
1 parent
4fa8108110
commit
abfa8c6a5c
32 files changed
+1058
-88
No files matched your search
@@ -107,7 +107,8 @@ KWin:
|
||||
- `kwin-effect-geometry-change-komorebi`
|
||||
([`nix/kwin-effect-geometry-change.nix`](nix/kwin-effect-geometry-change.nix)):
|
||||
Geometry Change 1.5, a scripted effect that animates a window that a program
|
||||
or a script moves or resizes.
|
||||
or a script moves or resizes, with a patch that makes its easing curve a
|
||||
setting.
|
||||
|
||||
Each one is a package for Linux and an attribute of `overlays.default`, built
|
||||
with the KWin of the nixpkgs the overlay is applied to.
|
||||
@@ -257,8 +258,8 @@ window, so the layout leaves the room while the compositor says it draws one, an
|
||||
komorebi gives each window the border color of what it is to the layout: the focused
|
||||
window, the others, a locked container, a floating window. `border`, `border-colour`,
|
||||
`border-width` and `border-offset` set it. Windows going to their places are
|
||||
animated by another effect, Geometry Change, which `animation` and
|
||||
`animation-duration` turn on and set.
|
||||
animated by another effect, Geometry Change, which `animation`,
|
||||
`animation-duration` and `animation-style` turn on and set.
|
||||
|
||||
## Documentation
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
```text
|
||||
Set the ease function for movement animations
|
||||
|
||||
Usage: animation-style [OPTIONS]
|
||||
|
||||
Options:
|
||||
-s, --style <STYLE>
|
||||
Desired ease function for animation
|
||||
|
||||
Possible values:
|
||||
- linear: Linear
|
||||
- ease-in-sine: Ease in sine
|
||||
- ease-out-sine: Ease out sine
|
||||
- ease-in-out-sine: Ease in out sine
|
||||
- ease-in-quad: Ease in quad
|
||||
- ease-out-quad: Ease out quad
|
||||
- ease-in-out-quad: Ease in out quad
|
||||
- ease-in-cubic: Ease in cubic
|
||||
- ease-out-cubic: Ease out cubic
|
||||
- ease-in-out-cubic: Ease in out cubic
|
||||
- ease-in-quart: Ease in quart
|
||||
- ease-out-quart: Ease out quart
|
||||
- ease-in-out-quart: Ease in out quart
|
||||
- ease-in-quint: Ease in quint
|
||||
- ease-out-quint: Ease out quint
|
||||
- ease-in-out-quint: Ease in out quint
|
||||
- ease-in-expo: Ease in expo
|
||||
- ease-out-expo: Ease out expo
|
||||
- ease-in-out-expo: Ease in out expo
|
||||
- ease-in-circ: Ease in circ
|
||||
- ease-out-circ: Ease out circ
|
||||
- ease-in-out-circ: Ease in out circ
|
||||
- ease-in-back: Ease in back
|
||||
- ease-out-back: Ease out back
|
||||
- ease-in-out-back: Ease in out back
|
||||
- ease-in-elastic: Ease in elastic
|
||||
- ease-out-elastic: Ease out elastic
|
||||
- ease-in-out-elastic: Ease in out elastic
|
||||
- ease-in-bounce: Ease in bounce
|
||||
- ease-out-bounce: Ease out bounce
|
||||
- ease-in-out-bounce: Ease in out bounce
|
||||
|
||||
[default: linear]
|
||||
|
||||
-a, --animation-type <ANIMATION_TYPE>
|
||||
Animation type to apply the style to. If not specified, sets global style
|
||||
|
||||
[possible values: movement]
|
||||
|
||||
-h, --help
|
||||
Print help (see a summary with '-h')
|
||||
|
||||
```
|
||||
@@ -69,7 +69,7 @@ grows with the code: each part of the daemon that is added has its place here.
|
||||
manager handles: the event or the message, and the state after it ([`Notification`]).
|
||||
- **Look**: how the compositor is asked to dress the windows, which it draws ([`Look`]):
|
||||
a border, with its width, its corner radius and two colors, and the animation of windows going
|
||||
to their places, with its duration.
|
||||
to their places, with its duration and its easing curve.
|
||||
- **Effect**: a plugin of the compositor that changes how windows are drawn. KDE Rounded Corners
|
||||
is the effect that draws the border, and Geometry Change the one that animates windows.
|
||||
- **Compositor**: the program that owns the screen and the windows. On KDE Plasma it is
|
||||
@@ -775,8 +775,9 @@ and answers whether borders are being drawn. The reasons are in
|
||||
[`border_manager`] holds the settings of the border, as statics that the messages `Border`,
|
||||
`BorderWidth` and `BorderOffset` set: whether borders are on, their width, the offset, the radius
|
||||
of the corners and the two colors. [`animation`] holds the settings of the animation, which
|
||||
`Animation`, `AnimationDuration` and `AnimationFps` set: whether windows are animated and for how
|
||||
long, for every kind of animation or for one ([`AnimationPrefix`]; movement is the only kind). The
|
||||
`Animation`, `AnimationDuration`, `AnimationStyle` and `AnimationFps` set: whether windows are
|
||||
animated, for how long and with what easing, for every kind of animation or for one
|
||||
([`AnimationPrefix`]; movement is the only kind). The
|
||||
settings of one kind win over the global ones, and a global setting clears the ones of the kinds.
|
||||
The commands that change a stack turn the animation off while they run and put it back, as
|
||||
komorebi does on the other platforms; the file's `animation` key sets the same settings.
|
||||
@@ -809,7 +810,10 @@ into the user's `kwinrc`, group `[Round-Corners]`, through [`Kwinrc`]; loads the
|
||||
look without a border unloads the effect, if komorebi loaded it, and puts the user's settings
|
||||
back. `shutdown` does the same. An effect KWin did not find when it started is reported once and
|
||||
komorebi goes on without it, with `apply_look` answering false. The animation is Geometry Change:
|
||||
its `Duration` is the look's, and cross-fading is off. KWin animates what is painted, so the
|
||||
its `Duration` and `Curve` are the look's, and cross-fading is off. The curve is a Qt easing
|
||||
curve, the name of the style without its "Ease" ([`AnimationStyle::qt_curve`]); the stock effect
|
||||
ignores `Curve` and eases out exponentially, and komorebi's build of it reads it. KWin animates
|
||||
what is painted, so the
|
||||
frame the table reads is the final one at once and nothing waits for an animation to end. The
|
||||
stock border effect has one color for
|
||||
the active window and one for the others; komorebi's build of it takes a color for each window,
|
||||
@@ -1059,9 +1063,10 @@ the fake. The window manager is its only caller, through [`backend`]. The contra
|
||||
| No outline is drawn inside a window, and a border is never thicker than the effect can draw | framework path: [`kwin::effects`](../../komorebi/src/kwin/effects.rs) sets every inner outline to 0 and clamps the width to 20 | `the_border_is_the_outer_outline_and_nothing_is_drawn_inside_the_window`, `a_border_thicker_than_the_effect_can_draw_is_the_thickest_it_can`, `vm-look` | none |
|
||||
| Every window has the border color of what it is to the layout, and a window whose kind changes has the new one at once | framework path: [`border_manager::update_colours`] is called after every event and every message, from [`border_manager::window_kinds`], and the backend sends the colors it did not send last time | `the_focused_window_has_the_focus_colour_and_the_others_do_not`, `a_locked_container_that_is_not_focused_is_marked`, `a_stack_has_its_own_colour_when_it_has_the_focus`, `a_monocled_window_has_the_monocle_colour`, `a_floating_window_has_the_floating_colour_while_it_has_the_focus`, `border_colours_are_a_command_only_when_they_change`, `vm-features` (section C) | the stock effect: two colors for every window |
|
||||
| With borders off no window has a color | framework path: [`border_manager::update_colours`] tells the backend an empty list when `BORDER_ENABLED` is false | `with_borders_off_no_window_has_a_colour` | none |
|
||||
| The settings of one kind of animation win over the global ones, and a global setting clears them | framework path: the arms of [`WindowManager::process_command`] for `Animation` and `AnimationDuration`, and [`animation::movement_animation`], which reads the kind's setting before the global one | `the_animation_messages_set_the_animation_and_the_compositor_is_asked_for_it` | none |
|
||||
| The settings of one kind of animation win over the global ones, and a global setting clears them | framework path: the arms of [`WindowManager::process_command`] for `Animation`, `AnimationDuration` and `AnimationStyle`, and [`animation::movement_animation`] and [`animation::movement_style`], which read the kind's setting before the global one | `the_animation_messages_set_the_animation_and_the_compositor_is_asked_for_it` | none |
|
||||
| A command that changes a stack is carried out with the animation off, and the animation is on again after it | framework path: the arms of [`WindowManager::process_command`] for the stack messages swap `ANIMATION_ENABLED_GLOBAL` for false and put the value back | `the_animation_is_on_again_after_a_command_that_changes_a_stack` | none |
|
||||
| The `animation` key of the file is the animation settings, and a file without it leaves them | framework path: `StaticConfig::apply_globals` sets them only when the key is there, and `duration` only when the key has one | `the_animation_key_of_the_file_is_the_animation_settings` | none |
|
||||
| The `animation` key of the file is the animation settings, and a file without it leaves them | framework path: `StaticConfig::apply_globals` sets them only when the key is there, and `duration` and `style` only when the key has one | `the_animation_key_of_the_file_is_the_animation_settings` | none |
|
||||
| Every style is a curve Qt has | test: [`AnimationStyle::qt_curve`] is a `match` of every style, and the test checks each against its name without the "Ease" | `every_style_is_a_curve_qt_has`, the doctest of `qt_curve`, `vm-features` (section D: two curves are in different places at the same moment) | a cubic Bézier is an ease out |
|
||||
| The effect komorebi loaded is unloaded, and the user's settings of it are put back, when komorebi stops using it or exits | framework path: the effect's state unloads what komorebi loaded, and [`Kwinrc`] puts the group back | `one_group_can_be_put_back_while_the_others_stay_changed`, `vm-look` | `SIGKILL`: the next run puts the settings back when it stops |
|
||||
| Queries never block on the compositor | convention only | none | the KWin backend's `cursor_pos` waits up to 250 ms |
|
||||
| Only the backend module reaches the compositor | convention only | none | none |
|
||||
@@ -1186,7 +1191,9 @@ A window is shown, and ends up on a tile:
|
||||
[`komorebi-border-colours.patch`](../../nix/kde-rounded-corners/komorebi-border-colours.patch),
|
||||
which lets komorebi give each window a color;
|
||||
[`nix/kwin-effect-geometry-change.nix`](../../nix/kwin-effect-geometry-change.nix), the
|
||||
effect that animates a window going to its place; and
|
||||
effect that animates a window going to its place, with
|
||||
[`curve.patch`](../../nix/kwin-effect-geometry-change/curve.patch), which makes its easing
|
||||
curve a setting; and
|
||||
[`nix/tests/effects.nix`](../../nix/tests/effects.nix), the checks of the files each effect
|
||||
package installs.
|
||||
- [`komorebi/tests/borders.rs`](../../komorebi/tests/borders.rs) and
|
||||
@@ -1287,6 +1294,8 @@ A window is shown, and ends up on a tile:
|
||||
[`BORDER_DRAWN`]: ../../komorebi/src/border_manager/mod.rs
|
||||
[`animation`]: ../../komorebi/src/animation/mod.rs
|
||||
[`animation::movement_animation`]: ../../komorebi/src/animation/mod.rs
|
||||
[`animation::movement_style`]: ../../komorebi/src/animation/mod.rs
|
||||
[`AnimationStyle::qt_curve`]: ../../komorebi/src/core/animation.rs
|
||||
[`AnimationPrefix`]: ../../komorebi/src/animation/prefix.rs
|
||||
[`Backend::set_border_colours`]: ../../komorebi/src/backend/mod.rs
|
||||
[`border_manager::window_kinds`]: ../../komorebi/src/border_manager/mod.rs
|
||||
|
||||
@@ -451,6 +451,15 @@ Because cross-fading the old contents of a window into the new while it changes
|
||||
effect's default, and it costs a redraw of both. A window going to its place is a move and a
|
||||
resize, and what the window shows does not change.
|
||||
|
||||
## Why are komorebi's animation styles Qt's easing curves?
|
||||
|
||||
Because KWin animates with `QEasingCurve`, and a style is a curve KWin has when it is Qt's name
|
||||
without the "Ease": `EaseInOutSine` is `InOutSine`
|
||||
([`AnimationStyle::qt_curve`](../../komorebi/src/core/animation.rs)). A custom cubic Bézier is not
|
||||
one of Qt's curves, and is drawn as an ease out, the kind of curve a window moving to its place
|
||||
wants. The stock Geometry Change has one curve, an exponential ease out, so komorebi's build of
|
||||
it reads a `Curve` setting ([PLATFORM.md](PLATFORM.md#the-patches)).
|
||||
|
||||
## Why are the effects patched?
|
||||
|
||||
Because the stock effects lack what komorebi needs of them. Each patch leaves the effect
|
||||
@@ -459,6 +468,7 @@ working without komorebi, with the settings the stock effect has:
|
||||
| Effect | Patched for | Why |
|
||||
|---|---|---|
|
||||
| KDE Rounded Corners | a color for each window, set over D-Bus; drawing a window again when its opacity changes | komorebi colors a window by what it is to the layout (the focused window of each monitor, a stack, a monocle, a floating window, a locked container), and the stock effect has one color for the active window and one for the others. It also draws a window from a texture that has the window's opacity in it, made again only when the contents change or the window is resized, so a change of opacity alone would not show |
|
||||
| Geometry Change | a `Curve` setting, the name of one of Qt's easing curves | komorebi's `animation.style` is an easing curve by name, and its named styles are Qt's curves with "Ease" in front (`EaseInOutSine` is Qt's `InOutSine`); the stock effect has one fixed curve, an exponential ease out, and no setting for it |
|
||||
|
||||
The patches are derivative works of the effects and are under the effects' license, the GNU
|
||||
General Public License version 3 ([PLATFORM.md](PLATFORM.md#the-patches)).
|
||||
+12
-4
@@ -459,11 +459,12 @@ At time of writing (2026-10-27):
|
||||
virtual machine loads 11 effects instead of 29.
|
||||
- **Geometry Change animates what a program or a script asks for**: a move and a resize made
|
||||
through KWin's scripting API are animated, and by its source an interactive move or resize
|
||||
is not. It eases out exponentially (`QEasingCurve.OutExpo`), so the movement is nearly
|
||||
over after a third of its duration. Its settings are in the
|
||||
is not. The stock effect always eases out exponentially (`QEasingCurve.OutExpo`), so the
|
||||
movement is nearly over after a third of its duration. Its settings are in the
|
||||
`[Effect-kwin4_effect_geometry_change]` group of `kwinrc` (`Duration`, `CrossFade`,
|
||||
`ExcludedWindowClasses`), and it reads them again on `reconfigureEffect`: a `Duration` of
|
||||
4000 written while it ran was the length of the next animation.
|
||||
`ExcludedWindowClasses`, and `Curve` with komorebi's patch), and it reads them again on
|
||||
`reconfigureEffect`: a `Duration` of 4000 written while it ran was the length of the next
|
||||
animation.
|
||||
- **The animation moves what is painted, not the window**: the frame KWin reports for the
|
||||
window (`frameGeometry`) is the final one from the start of the animation.
|
||||
|
||||
@@ -514,6 +515,12 @@ for KDE Rounded Corners, makes two changes:
|
||||
contents change or the window is resized, so a change of opacity alone would not show. The
|
||||
patched effect redirects the window again when its opacity changes.
|
||||
|
||||
[`curve.patch`](../../nix/kwin-effect-geometry-change/curve.patch), for Geometry Change, adds
|
||||
a `Curve` setting to the effect's group: the name of any of Qt's easing curves (`OutExpo`,
|
||||
`InOutSine`, ...), read with the effect's other settings and used for every animation. An
|
||||
unknown or missing name is the stock effect's curve, `OutExpo`. The check asserts that the
|
||||
script reads `Curve` and that the effect's settings declare it.
|
||||
|
||||
### What komorebi writes for the animation
|
||||
|
||||
Geometry Change reads its settings from the group `[Effect-kwin4_effect_geometry_change]` of
|
||||
@@ -523,6 +530,7 @@ Geometry Change reads its settings from the group `[Effect-kwin4_effect_geometry
|
||||
|---|---|
|
||||
| `Duration` | the animation's duration, in milliseconds |
|
||||
| `CrossFade` | `false`: a window that changes size is not cross-faded |
|
||||
| `Curve` | the name of a Qt easing curve (`Linear`, `OutExpo`, `InOutSine`, ...): komorebi's build of the effect reads it, and the stock effect ignores it |
|
||||
|
||||
komorebi then calls `reconfigureEffect`, and at time of writing (2026-10-27) the effect uses the
|
||||
new `Duration` for the next move: a `Duration` of 4000 written while it ran was the length of the
|
||||
|
||||
@@ -153,9 +153,11 @@ the run.
|
||||
reads the color of a pixel of a screenshot, and wants nothing else there.
|
||||
- `pixels` reads a screenshot: `pixels.pixel(image, x, y)` is the color of a
|
||||
pixel, `pixels.near(a, b)` compares two colors within a tolerance, since a
|
||||
compositor blends the edge of what it draws, and `pixels.ring(image, frame,
|
||||
compositor blends the edge of what it draws, `pixels.ring(image, frame,
|
||||
color)` names the sides of a window's frame that have no ring of `color` just
|
||||
outside them, which is how a test sees a border.
|
||||
outside them, which is how a test sees a border, and `pixels.leftmost(image,
|
||||
y, color)` finds where a row first has a color, which is how a test sees how
|
||||
far along a window is on its way.
|
||||
- `kwin_script(name, source, keep=)` runs a KWin script and returns the lines it
|
||||
reported: the script calls `report(...)`, which `print`s a line marked with
|
||||
`name` to KWin's log, and ends with `report("done")`. A script that is kept
|
||||
|
||||
+26
-5
@@ -2,7 +2,8 @@
|
||||
|
||||
komorebi can have a window slide to its new place when the layout changes, instead of jumping
|
||||
there. It does not animate anything itself: a KWin effect, Geometry Change, animates a window
|
||||
that a program or a script moves or resizes, and komorebi tells it how long the animation lasts.
|
||||
that a program or a script moves or resizes, and komorebi tells it how long the animation lasts
|
||||
and how it eases.
|
||||
Animation is off by default.
|
||||
|
||||
## Installing the effect
|
||||
@@ -41,23 +42,43 @@ komorebic animation-duration 600 --animation-type movement
|
||||
[`komorebic animation-fps`](../cli/animation-fps.md) is accepted and does nothing: KWin animates
|
||||
at the refresh rate of the screen.
|
||||
|
||||
## Easing
|
||||
|
||||
[`komorebic animation-style`](../cli/animation-style.md) sets the curve a window follows to its
|
||||
place: `linear` by default, or one of the easings by name (`ease-out-expo`, `ease-in-out-sine`,
|
||||
`ease-out-bounce`, ...; `komorebic animation-style --help` lists them). They are Qt's easing
|
||||
curves, and a style is Qt's name for the curve with the "Ease" taken off (`EaseInOutSine` is
|
||||
`InOutSine`). Like the others, it takes `--animation-type movement`.
|
||||
|
||||
```sh
|
||||
komorebic animation-style --style ease-out-expo
|
||||
komorebic animation-style --style ease-in-out-sine --animation-type movement
|
||||
```
|
||||
|
||||
The stock Geometry Change always eases out exponentially. The build the flake installs also reads
|
||||
the curve, which is what lets a style other than that one take effect; with the stock effect every
|
||||
style looks like an ease out. A cubic Bézier, which only a configuration can name, is not one of
|
||||
Qt's curves and is drawn as an ease out too.
|
||||
|
||||
## In komorebi.json
|
||||
|
||||
The `animation` key of [`komorebi.json`](configuration.md#animation) has the same settings:
|
||||
`enabled` and `duration`, each either one value for every kind of animation or a value for each
|
||||
kind (`{ "movement": true }`), and `fps`.
|
||||
`enabled`, `duration` and `style`, each either one value for every kind of animation or a value
|
||||
for each kind (`{ "movement": true }`), and `fps`.
|
||||
|
||||
```json
|
||||
{
|
||||
"animation": {
|
||||
"enabled": true,
|
||||
"duration": 400
|
||||
"duration": 400,
|
||||
"style": "EaseOutExpo"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The file sets them when the daemon starts and when the file changes. A file without the key leaves
|
||||
the settings as they are, and one with it that leaves out `duration` leaves the duration as it is.
|
||||
the settings as they are, and one with it that leaves out `duration` or `style` leaves that one as
|
||||
it is.
|
||||
|
||||
## What is animated
|
||||
|
||||
|
||||
@@ -113,11 +113,12 @@ runs.
|
||||
|---|---|---|
|
||||
| `enabled` | `false`, required | Whether windows are animated going to their places: `true` or `false` for every kind of animation, or `{ "movement": true }` for the kinds it names |
|
||||
| `duration` | `250` | How long the animation lasts, in milliseconds, in the same two forms |
|
||||
| `style` | `Linear` | The easing curve, in the same two forms: a name such as `EaseOutExpo`, or a cubic Bézier as four numbers ([Animation](animation.md#easing)) |
|
||||
| `fps` | `60` | Accepted and not used: KWin animates at the refresh rate of the screen |
|
||||
|
||||
[Animation](animation.md) explains what is animated. A file that has no `animation` leaves the
|
||||
settings as they are, and one that has it and leaves out `duration` leaves the duration as it is;
|
||||
`enabled` and `duration` given for every kind of animation take the settings of single kinds away.
|
||||
settings as they are, and one that has it and leaves out `duration` or `style` leaves that one as it
|
||||
is; a value given for every kind of animation takes the settings of single kinds away.
|
||||
|
||||
### Rules
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ pub use komorebi::core::SocketMessage;
|
||||
pub use komorebi::core::StateQuery;
|
||||
pub use komorebi::core::SubscribeOptions;
|
||||
pub use komorebi::core::WindowKind;
|
||||
pub use komorebi::core::animation::AnimationStyle;
|
||||
pub use komorebi::core::asc::ApplicationSpecificConfiguration;
|
||||
pub use komorebi::core::pathext::PathExt;
|
||||
pub use komorebi::core::pathext::replace_env_in_path;
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
//! `komorebi.json`).
|
||||
//!
|
||||
//! komorebi does not animate windows itself: KWin's Geometry Change effect animates a window going
|
||||
//! to its place. [`movement_animation`] is what the effect is told, in the
|
||||
//! [`Look`](crate::backend::Look) the border manager asks the backend for. The `fps` setting is
|
||||
//! stored and has nothing to map to: the compositor animates at the refresh rate of the screen.
|
||||
//! to its place. [`movement_animation`] and [`movement_style`] are what the effect is told, in the
|
||||
//! [`Look`](crate::backend::Look) the border manager asks the backend for. The stock effect has
|
||||
//! one curve, an exponential ease out; komorebi's build of it takes every style. The `fps`
|
||||
//! setting is stored and has nothing to map to: the compositor animates at the refresh rate of the
|
||||
//! screen.
|
||||
|
||||
use crate::core::animation::AnimationStyle;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
pub use prefix::AnimationPrefix;
|
||||
@@ -28,6 +32,7 @@ use serde::Serialize;
|
||||
/// ```json
|
||||
/// {
|
||||
/// "enabled": true,
|
||||
/// "style": "EaseInSine",
|
||||
/// "fps": 60,
|
||||
/// "duration": 250
|
||||
/// }
|
||||
@@ -38,6 +43,7 @@ use serde::Serialize;
|
||||
/// {
|
||||
/// "movement": {
|
||||
/// "enabled": true,
|
||||
/// "style": "EaseInSine",
|
||||
/// "fps": 60,
|
||||
/// "duration": 250
|
||||
/// }
|
||||
@@ -51,15 +57,23 @@ pub enum PerAnimationPrefixConfig<T> {
|
||||
}
|
||||
|
||||
pub const DEFAULT_ANIMATION_ENABLED: bool = false;
|
||||
pub const DEFAULT_ANIMATION_STYLE: AnimationStyle = AnimationStyle::Linear;
|
||||
pub const DEFAULT_ANIMATION_DURATION: u64 = 250;
|
||||
pub const DEFAULT_ANIMATION_FPS: u64 = 60;
|
||||
|
||||
pub static ANIMATION_STYLE_GLOBAL: LazyLock<Arc<Mutex<AnimationStyle>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(DEFAULT_ANIMATION_STYLE)));
|
||||
|
||||
pub static ANIMATION_ENABLED_GLOBAL: LazyLock<Arc<AtomicBool>> =
|
||||
LazyLock::new(|| Arc::new(AtomicBool::new(DEFAULT_ANIMATION_ENABLED)));
|
||||
|
||||
pub static ANIMATION_DURATION_GLOBAL: LazyLock<Arc<AtomicU64>> =
|
||||
LazyLock::new(|| Arc::new(AtomicU64::new(DEFAULT_ANIMATION_DURATION)));
|
||||
|
||||
pub static ANIMATION_STYLE_PER_ANIMATION: LazyLock<
|
||||
Arc<Mutex<HashMap<AnimationPrefix, AnimationStyle>>>,
|
||||
> = LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||
|
||||
pub static ANIMATION_ENABLED_PER_ANIMATION: LazyLock<Arc<Mutex<HashMap<AnimationPrefix, bool>>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||
|
||||
@@ -87,3 +101,12 @@ pub fn movement_animation() -> Option<u64> {
|
||||
.unwrap_or_else(|| ANIMATION_DURATION_GLOBAL.load(std::sync::atomic::Ordering::SeqCst))
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the easing of window movement: the `movement` style, else the global one.
|
||||
pub fn movement_style() -> AnimationStyle {
|
||||
ANIMATION_STYLE_PER_ANIMATION
|
||||
.lock()
|
||||
.get(&AnimationPrefix::Movement)
|
||||
.copied()
|
||||
.unwrap_or_else(|| *ANIMATION_STYLE_GLOBAL.lock())
|
||||
}
|
||||
@@ -119,7 +119,10 @@ pub struct MonitorInfo {
|
||||
/// focused: (66, 165, 245),
|
||||
/// unfocused: (128, 128, 128),
|
||||
/// }),
|
||||
/// animation: Some(AnimationLook { duration_ms: 250 }),
|
||||
/// animation: Some(AnimationLook {
|
||||
/// duration_ms: 250,
|
||||
/// curve: "InOutSine",
|
||||
/// }),
|
||||
/// };
|
||||
/// assert!(look.border.is_some() && look.animation.is_some());
|
||||
/// ```
|
||||
@@ -136,6 +139,8 @@ pub struct Look {
|
||||
pub struct AnimationLook {
|
||||
/// How long the animation of a window takes, in milliseconds.
|
||||
pub duration_ms: u64,
|
||||
/// The Qt easing curve of the animation, `QEasingCurve.<this>`.
|
||||
pub curve: &'static str,
|
||||
}
|
||||
|
||||
/// The outline around every window.
|
||||
|
||||
@@ -22,6 +22,7 @@ use crate::backend::BorderLook;
|
||||
use crate::backend::Look;
|
||||
use crate::backend::backend;
|
||||
use crate::core::WindowKind;
|
||||
use crate::core::animation::AnimationStyle;
|
||||
use crate::window_manager::WindowManager;
|
||||
use color_eyre::eyre;
|
||||
use lazy_static::lazy_static;
|
||||
@@ -230,21 +231,29 @@ pub static BORDER_DRAWN: AtomicBool = AtomicBool::new(false);
|
||||
///
|
||||
/// The border is there when `enabled`, with its width and radius at least 0; the colors are as the
|
||||
/// statics store them, red, green and blue in one number. The animation is a duration in
|
||||
/// milliseconds, when there is one.
|
||||
/// milliseconds and a style, when there is one.
|
||||
///
|
||||
/// ```rust
|
||||
/// use komorebi::border_manager::look;
|
||||
/// use komorebi::border_manager::pack;
|
||||
/// use komorebi::core::animation::AnimationStyle;
|
||||
///
|
||||
/// let blue = pack(66, 165, 245);
|
||||
/// let grey = pack(128, 128, 128);
|
||||
///
|
||||
/// let on = look(true, 8, -2, blue, grey, Some(250));
|
||||
/// let on = look(
|
||||
/// true,
|
||||
/// 8,
|
||||
/// -2,
|
||||
/// blue,
|
||||
/// grey,
|
||||
/// Some((250, AnimationStyle::EaseInOutSine)),
|
||||
/// );
|
||||
/// let border = on.border.expect("the borders are on");
|
||||
/// assert_eq!((border.width, border.radius), (8, 0));
|
||||
/// assert_eq!(border.focused, (66, 165, 245));
|
||||
/// assert_eq!(border.unfocused, (128, 128, 128));
|
||||
/// assert_eq!(on.animation.expect("an animation").duration_ms, 250);
|
||||
/// assert_eq!(on.animation.expect("an animation").curve, "InOutSine");
|
||||
///
|
||||
/// assert_eq!(look(false, 8, 10, blue, grey, None).border, None);
|
||||
/// ```
|
||||
@@ -254,7 +263,7 @@ pub fn look(
|
||||
radius: i32,
|
||||
focused: u32,
|
||||
unfocused: u32,
|
||||
animation: Option<u64>,
|
||||
animation: Option<(u64, AnimationStyle)>,
|
||||
) -> Look {
|
||||
Look {
|
||||
border: enabled.then(|| BorderLook {
|
||||
@@ -263,7 +272,10 @@ pub fn look(
|
||||
focused: unpack(focused),
|
||||
unfocused: unpack(unfocused),
|
||||
}),
|
||||
animation: animation.map(|duration_ms| AnimationLook { duration_ms }),
|
||||
animation: animation.map(|(duration_ms, style)| AnimationLook {
|
||||
duration_ms,
|
||||
curve: style.qt_curve(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +288,8 @@ pub fn current_look() -> Look {
|
||||
BORDER_RADIUS.load(Ordering::SeqCst),
|
||||
FOCUSED.load(Ordering::SeqCst),
|
||||
UNFOCUSED.load(Ordering::SeqCst),
|
||||
crate::animation::movement_animation(),
|
||||
crate::animation::movement_animation()
|
||||
.map(|duration| (duration, crate::animation::movement_style())),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -327,9 +340,36 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn borders_off_and_animation_on_are_independent() {
|
||||
let look = look(false, 10, 12, 0, 0, Some(250));
|
||||
let look = look(
|
||||
false,
|
||||
10,
|
||||
12,
|
||||
0,
|
||||
0,
|
||||
Some((250, AnimationStyle::EaseOutCubic)),
|
||||
);
|
||||
assert_eq!(look.border, None);
|
||||
assert_eq!(look.animation, Some(AnimationLook { duration_ms: 250 }));
|
||||
assert_eq!(
|
||||
look.animation,
|
||||
Some(AnimationLook {
|
||||
duration_ms: 250,
|
||||
curve: "OutCubic"
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_style_is_a_curve_qt_has() {
|
||||
// the names QEasingCurve has: komorebi's styles are those without the "Ease"
|
||||
for style in <AnimationStyle as clap::ValueEnum>::value_variants() {
|
||||
let name = format!("{style}");
|
||||
let expected = name.strip_prefix("Ease").unwrap_or(&name);
|
||||
assert_eq!(style.qt_curve(), expected, "{name}");
|
||||
}
|
||||
assert_eq!(
|
||||
AnimationStyle::CubicBezier(0.1, 0.2, 0.3, 0.4).qt_curve(),
|
||||
"OutCubic"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
//! The easing curves an animation can have (`komorebic animation-style`).
|
||||
|
||||
use clap::ValueEnum;
|
||||
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use serde::ser::SerializeSeq;
|
||||
use strum::Display;
|
||||
use strum::EnumString;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Display, EnumString, ValueEnum, PartialEq)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
/// Mathematical function which describes the rate at which a value changes
|
||||
pub enum AnimationStyle {
|
||||
/// Linear
|
||||
Linear,
|
||||
/// Ease in sine
|
||||
EaseInSine,
|
||||
/// Ease out sine
|
||||
EaseOutSine,
|
||||
/// Ease in out sine
|
||||
EaseInOutSine,
|
||||
/// Ease in quad
|
||||
EaseInQuad,
|
||||
/// Ease out quad
|
||||
EaseOutQuad,
|
||||
/// Ease in out quad
|
||||
EaseInOutQuad,
|
||||
/// Ease in cubic
|
||||
EaseInCubic,
|
||||
/// Ease out cubic
|
||||
EaseOutCubic,
|
||||
/// Ease in out cubic
|
||||
EaseInOutCubic,
|
||||
/// Ease in quart
|
||||
EaseInQuart,
|
||||
/// Ease out quart
|
||||
EaseOutQuart,
|
||||
/// Ease in out quart
|
||||
EaseInOutQuart,
|
||||
/// Ease in quint
|
||||
EaseInQuint,
|
||||
/// Ease out quint
|
||||
EaseOutQuint,
|
||||
/// Ease in out quint
|
||||
EaseInOutQuint,
|
||||
/// Ease in expo
|
||||
EaseInExpo,
|
||||
/// Ease out expo
|
||||
EaseOutExpo,
|
||||
/// Ease in out expo
|
||||
EaseInOutExpo,
|
||||
/// Ease in circ
|
||||
EaseInCirc,
|
||||
/// Ease out circ
|
||||
EaseOutCirc,
|
||||
/// Ease in out circ
|
||||
EaseInOutCirc,
|
||||
/// Ease in back
|
||||
EaseInBack,
|
||||
/// Ease out back
|
||||
EaseOutBack,
|
||||
/// Ease in out back
|
||||
EaseInOutBack,
|
||||
/// Ease in elastic
|
||||
EaseInElastic,
|
||||
/// Ease out elastic
|
||||
EaseOutElastic,
|
||||
/// Ease in out elastic
|
||||
EaseInOutElastic,
|
||||
/// Ease in bounce
|
||||
EaseInBounce,
|
||||
/// Ease out bounce
|
||||
EaseOutBounce,
|
||||
/// Ease in out bounce
|
||||
EaseInOutBounce,
|
||||
#[cfg_attr(feature = "schemars", schemars(title = "CubicBezier"))]
|
||||
#[value(skip)]
|
||||
/// Custom Cubic Bézier function
|
||||
CubicBezier(f64, f64, f64, f64),
|
||||
}
|
||||
|
||||
impl AnimationStyle {
|
||||
/// Returns the name of the Qt easing curve of this style, as KWin's animation API takes it
|
||||
/// (`QEasingCurve.<name>`).
|
||||
///
|
||||
/// The CSS-style easings are Qt's, without the "Ease". A custom cubic Bézier is not one of
|
||||
/// them, and is an ease out, the kind of curve a window moving to its place wants.
|
||||
///
|
||||
/// ```rust
|
||||
/// use komorebi::core::animation::AnimationStyle;
|
||||
///
|
||||
/// assert_eq!(AnimationStyle::Linear.qt_curve(), "Linear");
|
||||
/// assert_eq!(AnimationStyle::EaseInOutSine.qt_curve(), "InOutSine");
|
||||
/// assert_eq!(
|
||||
/// AnimationStyle::CubicBezier(0.3, 0.0, 0.2, 1.0).qt_curve(),
|
||||
/// "OutCubic"
|
||||
/// );
|
||||
/// ```
|
||||
pub const fn qt_curve(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Linear => "Linear",
|
||||
Self::EaseInSine => "InSine",
|
||||
Self::EaseOutSine => "OutSine",
|
||||
Self::EaseInOutSine => "InOutSine",
|
||||
Self::EaseInQuad => "InQuad",
|
||||
Self::EaseOutQuad => "OutQuad",
|
||||
Self::EaseInOutQuad => "InOutQuad",
|
||||
Self::EaseInCubic => "InCubic",
|
||||
Self::EaseOutCubic => "OutCubic",
|
||||
Self::EaseInOutCubic => "InOutCubic",
|
||||
Self::EaseInQuart => "InQuart",
|
||||
Self::EaseOutQuart => "OutQuart",
|
||||
Self::EaseInOutQuart => "InOutQuart",
|
||||
Self::EaseInQuint => "InQuint",
|
||||
Self::EaseOutQuint => "OutQuint",
|
||||
Self::EaseInOutQuint => "InOutQuint",
|
||||
Self::EaseInExpo => "InExpo",
|
||||
Self::EaseOutExpo => "OutExpo",
|
||||
Self::EaseInOutExpo => "InOutExpo",
|
||||
Self::EaseInCirc => "InCirc",
|
||||
Self::EaseOutCirc => "OutCirc",
|
||||
Self::EaseInOutCirc => "InOutCirc",
|
||||
Self::EaseInBack => "InBack",
|
||||
Self::EaseOutBack => "OutBack",
|
||||
Self::EaseInOutBack => "InOutBack",
|
||||
Self::EaseInElastic => "InElastic",
|
||||
Self::EaseOutElastic => "OutElastic",
|
||||
Self::EaseInOutElastic => "InOutElastic",
|
||||
Self::EaseInBounce => "InBounce",
|
||||
Self::EaseOutBounce => "OutBounce",
|
||||
Self::EaseInOutBounce => "InOutBounce",
|
||||
Self::CubicBezier(..) => "OutCubic",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom serde implementation
|
||||
impl<'de> Deserialize<'de> for AnimationStyle {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
struct AnimationStyleVisitor;
|
||||
|
||||
impl<'de> serde::de::Visitor<'de> for AnimationStyleVisitor {
|
||||
type Value = AnimationStyle;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
formatter.write_str("a string or an array of four f64 values")
|
||||
}
|
||||
|
||||
// Handle string variants (e.g., "EaseInOutExpo")
|
||||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
value.parse().map_err(|_| E::unknown_variant(value, &[]))
|
||||
}
|
||||
|
||||
// Handle CubicBezier array (e.g., [0.32, 0.72, 0.0, 1.0])
|
||||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
|
||||
where
|
||||
A: serde::de::SeqAccess<'de>,
|
||||
{
|
||||
let x1 = seq
|
||||
.next_element()?
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(0, &self))?;
|
||||
let y1 = seq
|
||||
.next_element()?
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(1, &self))?;
|
||||
let x2 = seq
|
||||
.next_element()?
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(2, &self))?;
|
||||
let y2 = seq
|
||||
.next_element()?
|
||||
.ok_or_else(|| serde::de::Error::invalid_length(3, &self))?;
|
||||
|
||||
// Ensure no extra elements
|
||||
if seq.next_element::<serde::de::IgnoredAny>()?.is_some() {
|
||||
return Err(serde::de::Error::invalid_length(5, &self));
|
||||
}
|
||||
|
||||
Ok(AnimationStyle::CubicBezier(x1, y1, x2, y2))
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_any(AnimationStyleVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for AnimationStyle {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
match self {
|
||||
// Serialize CubicBezier as an array
|
||||
AnimationStyle::CubicBezier(x1, y1, x2, y2) => {
|
||||
let mut seq = serializer.serialize_seq(Some(4))?;
|
||||
seq.serialize_element(x1)?;
|
||||
seq.serialize_element(y1)?;
|
||||
seq.serialize_element(x2)?;
|
||||
seq.serialize_element(y2)?;
|
||||
seq.end()
|
||||
}
|
||||
// Serialize all other variants as strings
|
||||
_ => serializer.serialize_str(&self.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_style_is_written_as_its_name_and_a_bezier_as_four_numbers() {
|
||||
assert_eq!(
|
||||
serde_json::to_string(&AnimationStyle::EaseInOutSine).unwrap(),
|
||||
r#""EaseInOutSine""#
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&AnimationStyle::CubicBezier(0.32, 0.72, 0.0, 1.0)).unwrap(),
|
||||
"[0.32,0.72,0.0,1.0]"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_style_is_read_back_from_what_it_is_written_as() {
|
||||
for style in [
|
||||
AnimationStyle::Linear,
|
||||
AnimationStyle::EaseOutBounce,
|
||||
AnimationStyle::CubicBezier(0.1, 0.2, 0.3, 0.4),
|
||||
] {
|
||||
let json = serde_json::to_string(&style).unwrap();
|
||||
assert_eq!(
|
||||
serde_json::from_str::<AnimationStyle>(&json).unwrap(),
|
||||
style
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_that_is_no_style_and_a_bezier_that_is_not_four_numbers_are_refused() {
|
||||
assert!(serde_json::from_str::<AnimationStyle>(r#""EaseInPlace""#).is_err());
|
||||
assert!(serde_json::from_str::<AnimationStyle>("[0.1, 0.2, 0.3]").is_err());
|
||||
assert!(serde_json::from_str::<AnimationStyle>("[0.1, 0.2, 0.3, 0.4, 0.5]").is_err());
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
//! previous container in the order of the workspace.
|
||||
|
||||
use crate::animation::AnimationPrefix;
|
||||
use crate::core::animation::AnimationStyle;
|
||||
use crate::core::pathext::ResolvedPathBuf;
|
||||
use clap::ValueEnum;
|
||||
use color_eyre::eyre;
|
||||
@@ -46,6 +47,7 @@ pub use komorebi_layouts::Sizing;
|
||||
pub use komorebi_layouts::validate_ratios;
|
||||
|
||||
// Keep local modules that aren't in komorebi-layouts
|
||||
pub mod animation;
|
||||
pub mod asc;
|
||||
pub mod config_generation;
|
||||
pub mod pathext;
|
||||
@@ -474,6 +476,7 @@ pub enum SocketMessage {
|
||||
Animation(bool, Option<AnimationPrefix>),
|
||||
AnimationDuration(u64, Option<AnimationPrefix>),
|
||||
AnimationFps(u64),
|
||||
AnimationStyle(AnimationStyle, Option<AnimationPrefix>),
|
||||
#[serde(alias = "ActiveWindowBorder")]
|
||||
Border(bool),
|
||||
#[serde(alias = "ActiveWindowBorderColour")]
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
//! installed later cannot be loaded until the next login. An effect that is not installed is
|
||||
//! reported once in the log, and komorebi carries on without it.
|
||||
//!
|
||||
//! komorebi's build of the border effect (`nix/kde-rounded-corners.nix`) adds what the stock one
|
||||
//! lacks: a border color for each window, set over D-Bus with
|
||||
//! [`EffectsState::set_window_colours`].
|
||||
//! komorebi's builds of the two effects (`nix/kde-rounded-corners.nix`,
|
||||
//! `nix/kwin-effect-geometry-change.nix`) add what the stock ones lack: a border color for each
|
||||
//! window, set over D-Bus with [`EffectsState::set_window_colours`], and a choice of easing curve
|
||||
//! (the `Curve` setting).
|
||||
//!
|
||||
//! # What is guaranteed, and by what
|
||||
//!
|
||||
@@ -137,11 +138,16 @@ pub fn border_settings(border: &BorderLook) -> Vec<(&'static str, String)> {
|
||||
/// the effect's default and costs a redraw of both; a window going to its place is a move and a
|
||||
/// resize, not a change of what it shows.
|
||||
///
|
||||
/// `Curve` is not a setting of the stock effect, which always eases out exponentially. komorebi's
|
||||
/// build of it (`nix/kwin-effect-geometry-change.nix`) reads it, and the stock effect ignores the
|
||||
/// key.
|
||||
///
|
||||
/// Covered by `kwin::effects::tests::animation_is_a_duration_without_cross_fading`.
|
||||
pub fn animation_settings(animation: &AnimationLook) -> Vec<(&'static str, String)> {
|
||||
vec![
|
||||
("Duration", animation.duration_ms.to_string()),
|
||||
("CrossFade", "false".to_string()),
|
||||
("Curve", animation.curve.to_string()),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -446,11 +452,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn animation_is_a_duration_without_cross_fading() {
|
||||
let s: std::collections::HashMap<_, _> =
|
||||
animation_settings(&AnimationLook { duration_ms: 250 })
|
||||
.into_iter()
|
||||
.collect();
|
||||
let s: std::collections::HashMap<_, _> = animation_settings(&AnimationLook {
|
||||
duration_ms: 250,
|
||||
curve: "InOutSine",
|
||||
})
|
||||
.into_iter()
|
||||
.collect();
|
||||
assert_eq!(s["Duration"], "250");
|
||||
assert_eq!(s["CrossFade"], "false");
|
||||
assert_eq!(s["Curve"], "InOutSine");
|
||||
}
|
||||
}
|
||||
@@ -183,10 +183,11 @@
|
||||
//! ([`WindowKind`]), and every message, once handled, tells the backend the color of each
|
||||
//! window's border ([`border_manager::update_colours`]).
|
||||
//! - **Animation** sets whether windows are animated going to their places, **AnimationDuration**
|
||||
//! for how long, and **AnimationFps** the frame rate that is stored and has nothing to map to
|
||||
//! (the compositor animates at the refresh rate of the screen); each is for every kind of
|
||||
//! animation or, given an [`AnimationPrefix`](crate::animation::AnimationPrefix), for one. The
|
||||
//! look asked of the backend after the message has the animation.
|
||||
//! for how long, **AnimationStyle** the easing curve, and **AnimationFps** the frame rate that is
|
||||
//! stored and has nothing to map to (the compositor animates at the refresh rate of the
|
||||
//! screen); each is for every kind of animation or, given an
|
||||
//! [`AnimationPrefix`](crate::animation::AnimationPrefix), for one. The look asked of the
|
||||
//! backend after the message has the animation.
|
||||
//! - **Retile** tiles the focused workspace of every monitor again, without the resize
|
||||
//! adjustments, and **RetileWithResizeDimensions** with them.
|
||||
//! - **AddSubscriberSocket** and **AddSubscriberSocketWithOptions** add a subscriber by the name
|
||||
@@ -213,6 +214,8 @@ use crate::animation::ANIMATION_DURATION_PER_ANIMATION;
|
||||
use crate::animation::ANIMATION_ENABLED_GLOBAL;
|
||||
use crate::animation::ANIMATION_ENABLED_PER_ANIMATION;
|
||||
use crate::animation::ANIMATION_FPS;
|
||||
use crate::animation::ANIMATION_STYLE_GLOBAL;
|
||||
use crate::animation::ANIMATION_STYLE_PER_ANIMATION;
|
||||
use crate::backend::backend;
|
||||
use crate::border_manager;
|
||||
use crate::core::ApplicationIdentifier;
|
||||
@@ -2023,6 +2026,16 @@ impl WindowManager {
|
||||
SocketMessage::AnimationFps(fps) => {
|
||||
ANIMATION_FPS.store(fps, Ordering::SeqCst);
|
||||
}
|
||||
SocketMessage::AnimationStyle(style, prefix) => match prefix {
|
||||
Some(prefix) => {
|
||||
ANIMATION_STYLE_PER_ANIMATION.lock().insert(prefix, style);
|
||||
}
|
||||
None => {
|
||||
let mut animation_style = ANIMATION_STYLE_GLOBAL.lock();
|
||||
*animation_style = style;
|
||||
ANIMATION_STYLE_PER_ANIMATION.lock().clear();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
self.update_known_window_ids();
|
||||
|
||||
@@ -42,6 +42,8 @@ use crate::animation::ANIMATION_DURATION_PER_ANIMATION;
|
||||
use crate::animation::ANIMATION_ENABLED_GLOBAL;
|
||||
use crate::animation::ANIMATION_ENABLED_PER_ANIMATION;
|
||||
use crate::animation::ANIMATION_FPS;
|
||||
use crate::animation::ANIMATION_STYLE_GLOBAL;
|
||||
use crate::animation::ANIMATION_STYLE_PER_ANIMATION;
|
||||
use crate::animation::DEFAULT_ANIMATION_FPS;
|
||||
use crate::animation::PerAnimationPrefixConfig;
|
||||
use crate::border_manager;
|
||||
@@ -61,6 +63,7 @@ use crate::core::SocketMessage;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::core::WindowManagementBehaviour;
|
||||
use crate::core::animation::AnimationStyle;
|
||||
use crate::core::asc::ApplicationSpecificConfiguration;
|
||||
use crate::core::asc::AscApplicationRulesOrSchema;
|
||||
use crate::core::config_generation::MatchingRule;
|
||||
@@ -527,6 +530,10 @@ pub struct AnimationsConfig {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = PerAnimationPrefixConfig::Global(250))))]
|
||||
pub duration: Option<PerAnimationPrefixConfig<u64>>,
|
||||
/// Set the animation style
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = PerAnimationPrefixConfig::Global(AnimationStyle::Linear))))]
|
||||
pub style: Option<PerAnimationPrefixConfig<AnimationStyle>>,
|
||||
/// Set the animation FPS
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(feature = "schemars", schemars(extend("default" = DEFAULT_ANIMATION_FPS)))]
|
||||
@@ -705,6 +712,18 @@ impl StaticConfig {
|
||||
}
|
||||
}
|
||||
|
||||
match &animations.style {
|
||||
Some(PerAnimationPrefixConfig::Prefix(style)) => {
|
||||
ANIMATION_STYLE_PER_ANIMATION.lock().clone_from(style);
|
||||
}
|
||||
Some(PerAnimationPrefixConfig::Global(style)) => {
|
||||
let mut animation_style = ANIMATION_STYLE_GLOBAL.lock();
|
||||
*animation_style = *style;
|
||||
ANIMATION_STYLE_PER_ANIMATION.lock().clear();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
match &animations.duration {
|
||||
Some(PerAnimationPrefixConfig::Prefix(duration)) => {
|
||||
ANIMATION_DURATION_PER_ANIMATION.lock().clone_from(duration);
|
||||
|
||||
@@ -11,6 +11,7 @@ use komorebi::backend::fake::Command;
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
use komorebi::backend::with_backend;
|
||||
use komorebi::core::SocketMessage;
|
||||
use komorebi::core::animation::AnimationStyle;
|
||||
use komorebi::window_manager::WindowManager;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::Ordering;
|
||||
@@ -40,29 +41,45 @@ fn the_animation_messages_set_the_animation_and_the_compositor_is_asked_for_it()
|
||||
})
|
||||
.expect("the compositor was asked for a look")
|
||||
};
|
||||
let animated = |duration_ms| Some(AnimationLook { duration_ms });
|
||||
let animated = |duration_ms, curve| Some(AnimationLook { duration_ms, curve });
|
||||
let movement = Some(AnimationPrefix::Movement);
|
||||
|
||||
// nothing is animated until it is asked for, and then for the default time
|
||||
send(&mut wm, SocketMessage::BorderWidth(10));
|
||||
assert_eq!(animation(), None);
|
||||
send(&mut wm, SocketMessage::Animation(true, None));
|
||||
assert_eq!(animation(), animated(250));
|
||||
assert_eq!(animation(), animated(250, "Linear"));
|
||||
|
||||
send(&mut wm, SocketMessage::AnimationDuration(120, None));
|
||||
assert_eq!(animation(), animated(120));
|
||||
assert_eq!(animation(), animated(120, "Linear"));
|
||||
|
||||
// the easing is a Qt curve: the style without its "Ease"
|
||||
send(
|
||||
&mut wm,
|
||||
SocketMessage::AnimationStyle(AnimationStyle::EaseOutExpo, None),
|
||||
);
|
||||
assert_eq!(animation(), animated(120, "OutExpo"));
|
||||
|
||||
// the settings of one kind of animation win over the global ones
|
||||
send(&mut wm, SocketMessage::Animation(false, movement));
|
||||
assert_eq!(animation(), None);
|
||||
send(&mut wm, SocketMessage::AnimationDuration(500, movement));
|
||||
assert_eq!(animation(), None);
|
||||
send(
|
||||
&mut wm,
|
||||
SocketMessage::AnimationStyle(AnimationStyle::EaseInSine, movement),
|
||||
);
|
||||
send(&mut wm, SocketMessage::Animation(true, movement));
|
||||
assert_eq!(animation(), animated(500));
|
||||
assert_eq!(animation(), animated(500, "InSine"));
|
||||
|
||||
// and a global setting takes the ones of the kinds away
|
||||
send(&mut wm, SocketMessage::AnimationDuration(90, None));
|
||||
assert_eq!(animation(), animated(90));
|
||||
assert_eq!(animation(), animated(90, "InSine"));
|
||||
send(
|
||||
&mut wm,
|
||||
SocketMessage::AnimationStyle(AnimationStyle::Linear, None),
|
||||
);
|
||||
assert_eq!(animation(), animated(90, "Linear"));
|
||||
send(&mut wm, SocketMessage::Animation(false, None));
|
||||
assert_eq!(animation(), None);
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@
|
||||
use color_eyre::eyre;
|
||||
use komorebi::animation::ANIMATION_FPS;
|
||||
use komorebi::animation::movement_animation;
|
||||
use komorebi::animation::movement_style;
|
||||
use komorebi::backend::fake::FakeBackend;
|
||||
use komorebi::backend::with_backend;
|
||||
use komorebi::core::animation::AnimationStyle;
|
||||
use komorebi::static_config::StaticConfig;
|
||||
use komorebi::window_manager::WindowManager;
|
||||
use parking_lot::Mutex;
|
||||
@@ -30,7 +32,7 @@ fn the_animation_key_of_the_file_is_the_animation_settings() {
|
||||
|
||||
let path = write_config(
|
||||
"all",
|
||||
r#"{ "animation": { "enabled": true, "duration": 120, "fps": 30 } }"#,
|
||||
r#"{ "animation": { "enabled": true, "duration": 120, "style": "EaseOutExpo", "fps": 30 } }"#,
|
||||
);
|
||||
let (_sender, receiver) = crossbeam_channel::bounded(1);
|
||||
let socket = PathBuf::from(format!("/tmp/kmb-anim-config-{}.sock", std::process::id()));
|
||||
@@ -48,17 +50,20 @@ fn the_animation_key_of_the_file_is_the_animation_settings() {
|
||||
|
||||
// one value for every kind of animation
|
||||
assert_eq!(movement_animation(), Some(120));
|
||||
assert_eq!(movement_style(), AnimationStyle::EaseOutExpo);
|
||||
assert_eq!(ANIMATION_FPS.load(Ordering::SeqCst), 30);
|
||||
|
||||
// a value for the kinds a file names wins over the global ones, which a global value takes away
|
||||
let by_kind = write_config(
|
||||
"kind",
|
||||
r#"{ "animation": { "enabled": { "movement": false }, "duration": { "movement": 500 } } }"#,
|
||||
r#"{ "animation": { "enabled": { "movement": false }, "duration": { "movement": 500 },
|
||||
"style": { "movement": "EaseInOutSine" } } }"#,
|
||||
);
|
||||
with_backend(fake.clone(), || {
|
||||
StaticConfig::reload(&by_kind, &mut wm.lock()).unwrap();
|
||||
});
|
||||
assert_eq!(movement_animation(), None, "movement is off");
|
||||
assert_eq!(movement_style(), AnimationStyle::EaseInOutSine);
|
||||
assert_eq!(
|
||||
ANIMATION_FPS.load(Ordering::SeqCst),
|
||||
60,
|
||||
@@ -67,14 +72,19 @@ fn the_animation_key_of_the_file_is_the_animation_settings() {
|
||||
|
||||
let on = write_config(
|
||||
"on",
|
||||
r#"{ "animation": { "enabled": { "movement": true }, "duration": 90 } }"#,
|
||||
r#"{ "animation": { "enabled": { "movement": true }, "duration": 90, "style": "Linear" } }"#,
|
||||
);
|
||||
with_backend(fake.clone(), || {
|
||||
StaticConfig::reload(&on, &mut wm.lock()).unwrap();
|
||||
});
|
||||
assert_eq!(movement_animation(), Some(90), "a global duration wins");
|
||||
assert_eq!(
|
||||
movement_style(),
|
||||
AnimationStyle::Linear,
|
||||
"and so does a global style"
|
||||
);
|
||||
|
||||
// a file that leaves the key out, or the duration, leaves the settings as they are
|
||||
// a file that leaves the key out, or the duration and the style, leaves the settings as they are
|
||||
let empty = write_config("empty", "{}");
|
||||
with_backend(fake.clone(), || {
|
||||
StaticConfig::reload(&empty, &mut wm.lock()).unwrap();
|
||||
@@ -85,6 +95,7 @@ fn the_animation_key_of_the_file_is_the_animation_settings() {
|
||||
StaticConfig::reload(&no_duration, &mut wm.lock()).unwrap();
|
||||
});
|
||||
assert_eq!(movement_animation(), Some(90));
|
||||
assert_eq!(movement_style(), AnimationStyle::Linear);
|
||||
|
||||
// `enabled` is the one key the file has to give
|
||||
assert!(StaticConfig::read_raw(r#"{ "animation": { "duration": 100 } }"#).is_err());
|
||||
|
||||
@@ -59,7 +59,13 @@ fn the_animation_is_on_again_after_a_command_that_changes_a_stack() {
|
||||
};
|
||||
|
||||
send(&mut wm, SocketMessage::Animation(true, None));
|
||||
assert_eq!(animation(), Some(AnimationLook { duration_ms: 250 }));
|
||||
assert_eq!(
|
||||
animation(),
|
||||
Some(AnimationLook {
|
||||
duration_ms: 250,
|
||||
curve: "Linear",
|
||||
})
|
||||
);
|
||||
|
||||
// every look the compositor is asked for while the command runs, as what it animates
|
||||
let looks = || {
|
||||
@@ -71,7 +77,10 @@ fn the_animation_is_on_again_after_a_command_that_changes_a_stack() {
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
let on = Some(AnimationLook { duration_ms: 250 });
|
||||
let on = Some(AnimationLook {
|
||||
duration_ms: 250,
|
||||
curve: "Linear",
|
||||
});
|
||||
|
||||
for (message, asked) in [
|
||||
(SocketMessage::StackWindow(OperationDirection::Left), vec![]),
|
||||
|
||||
+22
-2
@@ -69,8 +69,9 @@
|
||||
//! - `border` sets whether the compositor draws a border around each window, `border-colour` the
|
||||
//! color of the border of a kind of window, and `border-width` and `border-offset` the room the
|
||||
//! layout leaves for it.
|
||||
//! - `animation`, `animation-duration` and `animation-fps` set whether windows are animated going
|
||||
//! to their places, for how long, and the frame rate that is stored and ignored.
|
||||
//! - `animation`, `animation-duration` and `animation-style` set whether windows are animated going
|
||||
//! to their places, for how long and with what easing, and `animation-fps` the frame rate that
|
||||
//! is stored and ignored.
|
||||
//!
|
||||
//! `ignore-rule` and `manage-rule` add a rule that keeps an application out of the layout or
|
||||
//! always in it, `session-float-rule` floats the focused window and every window like it until the
|
||||
@@ -781,6 +782,16 @@ struct AnimationFps {
|
||||
fps: u64,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct AnimationStyle {
|
||||
/// Desired ease function for animation
|
||||
#[clap(value_enum, short, long, default_value = "linear")]
|
||||
style: komorebi_client::AnimationStyle,
|
||||
/// Animation type to apply the style to. If not specified, sets global style
|
||||
#[clap(value_enum, short, long)]
|
||||
animation_type: Option<komorebi_client::AnimationPrefix>,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Docgen {
|
||||
/// Output directory for generated documentation files
|
||||
@@ -1227,6 +1238,9 @@ enum SubCommand {
|
||||
/// Set the frames per second for movement animations
|
||||
#[clap(arg_required_else_help = true)]
|
||||
AnimationFps(AnimationFps),
|
||||
/// Set the ease function for movement animations
|
||||
#[clap(arg_required_else_help = true)]
|
||||
AnimationStyle(AnimationStyle),
|
||||
/// Enable or disable mouse follows focus on all workspaces
|
||||
#[clap(arg_required_else_help = true)]
|
||||
MouseFollowsFocus(MouseFollowsFocus),
|
||||
@@ -2066,6 +2080,12 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::AnimationFps(args) => {
|
||||
send_message(&SocketMessage::AnimationFps(args.fps))?;
|
||||
}
|
||||
SubCommand::AnimationStyle(args) => {
|
||||
send_message(&SocketMessage::AnimationStyle(
|
||||
args.style,
|
||||
args.animation_type,
|
||||
))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -530,6 +530,14 @@ fn the_animation_subcommands_send_what_they_are_given() {
|
||||
&["animation-duration", "500", "-a", "movement"],
|
||||
r#"{"type":"AnimationDuration","content":[500,"movement"]}"#,
|
||||
);
|
||||
sends(
|
||||
&["animation-style", "--style", "ease-in-out-sine"],
|
||||
r#"{"type":"AnimationStyle","content":["EaseInOutSine",null]}"#,
|
||||
);
|
||||
sends(
|
||||
&["animation-style", "-a", "movement"],
|
||||
r#"{"type":"AnimationStyle","content":["Linear","movement"]}"#,
|
||||
);
|
||||
sends(
|
||||
&["animation-fps", "30"],
|
||||
r#"{"type":"AnimationFps","content":30}"#,
|
||||
@@ -1055,6 +1063,7 @@ fn docgen_writes_the_help_of_every_subcommand_in_a_text_fence() {
|
||||
"adjust-workspace-padding.md",
|
||||
"animation-duration.md",
|
||||
"animation-fps.md",
|
||||
"animation-style.md",
|
||||
"animation.md",
|
||||
"application-specific-configuration-schema.md",
|
||||
"border-colour.md",
|
||||
|
||||
@@ -1,6 +1,51 @@
|
||||
# schema-sha256: e53fa2caa5377453b0cb6e1302e8ef951904fd38a488df1ad75997cd6fb97ea1
|
||||
# schema-sha256: 775a2171f74c90914b3de3fd6eed52485bd52cc19c881c90c56f60c36b91611e
|
||||
{ lib, ... }:
|
||||
let
|
||||
animationStyle = (
|
||||
lib.types.oneOf [
|
||||
(lib.types.enum [
|
||||
"Linear"
|
||||
"EaseInSine"
|
||||
"EaseOutSine"
|
||||
"EaseInOutSine"
|
||||
"EaseInQuad"
|
||||
"EaseOutQuad"
|
||||
"EaseInOutQuad"
|
||||
"EaseInCubic"
|
||||
"EaseOutCubic"
|
||||
"EaseInOutCubic"
|
||||
"EaseInQuart"
|
||||
"EaseOutQuart"
|
||||
"EaseInOutQuart"
|
||||
"EaseInQuint"
|
||||
"EaseOutQuint"
|
||||
"EaseInOutQuint"
|
||||
"EaseInExpo"
|
||||
"EaseOutExpo"
|
||||
"EaseInOutExpo"
|
||||
"EaseInCirc"
|
||||
"EaseOutCirc"
|
||||
"EaseInOutCirc"
|
||||
"EaseInBack"
|
||||
"EaseOutBack"
|
||||
"EaseInOutBack"
|
||||
"EaseInElastic"
|
||||
"EaseOutElastic"
|
||||
"EaseInOutElastic"
|
||||
"EaseInBounce"
|
||||
"EaseOutBounce"
|
||||
"EaseInOutBounce"
|
||||
])
|
||||
(lib.types.submodule {
|
||||
options = {
|
||||
CubicBezier = lib.mkOption {
|
||||
type = (lib.types.nullOr (lib.types.listOf lib.types.number));
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
})
|
||||
]
|
||||
);
|
||||
defaultLayout = (
|
||||
lib.types.enum [
|
||||
"BSP"
|
||||
@@ -205,6 +250,24 @@ in
|
||||
default = 60;
|
||||
description = "Set the animation FPS";
|
||||
};
|
||||
style = lib.mkOption {
|
||||
type = (
|
||||
lib.types.nullOr (
|
||||
lib.types.oneOf [
|
||||
(lib.types.submodule {
|
||||
options = {
|
||||
movement = lib.mkOption {
|
||||
type = animationStyle;
|
||||
};
|
||||
};
|
||||
})
|
||||
animationStyle
|
||||
]
|
||||
)
|
||||
);
|
||||
default = "Linear";
|
||||
description = "Set the animation style";
|
||||
};
|
||||
};
|
||||
}
|
||||
)
|
||||
|
||||
@@ -19,6 +19,10 @@ stdenvNoCC.mkDerivation {
|
||||
hash = "sha256-aJx3hDzIk/bQrrRvs/CPigJ0miTgqxd8OI9I6kuiXkk=";
|
||||
};
|
||||
|
||||
# `Curve`: any of Qt's easing curves by name, which is how komorebi's `animation.style` reaches the
|
||||
# effect (it has one fixed curve, an ease out exponential, and no setting for it)
|
||||
patches = [ ./kwin-effect-geometry-change/curve.patch ];
|
||||
|
||||
dontBuild = true;
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
curve.patch, for Geometry Change at revision 398491e
|
||||
(https://github.com/peterfajdiga/kwin4_effect_geometry_change), applied by
|
||||
nix/kwin-effect-geometry-change.nix. It adds a Curve setting: any of Qt's
|
||||
easing curves by name (OutExpo, InOutSine, ...), which is how komorebi sets
|
||||
the curve of its animations. An unknown or missing name is the effect's own
|
||||
curve, OutExpo.
|
||||
|
||||
This patch is a derivative work of Geometry Change, which is distributed under
|
||||
the GNU General Public License version 3, and it is distributed under the same
|
||||
license.
|
||||
|
||||
SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
diff -ruN a/package/contents/code/main.js b/package/contents/code/main.js
|
||||
--- a/package/contents/code/main.js 2026-10-26 21:55:40
|
||||
+++ b/package/contents/code/main.js 2026-10-26 21:55:40
|
||||
@@ -17,6 +17,12 @@
|
||||
this.duration = animationTime(duration);
|
||||
this.excludedWindowClasses = effect.readConfig("ExcludedWindowClasses", "krunner,yakuake").split(",");
|
||||
this.crossFade = effect.readConfig("CrossFade", false);
|
||||
+ // komorebi: any of Qt's easing curves by name ("OutExpo", "InOutSine", ...), which is how it
|
||||
+ // says what its `animation.style` is; an unknown or missing name is the effect's own curve
|
||||
+ this.curve = QEasingCurve[effect.readConfig("Curve", "OutExpo")];
|
||||
+ if (this.curve === undefined) {
|
||||
+ this.curve = QEasingCurve.OutExpo;
|
||||
+ }
|
||||
}
|
||||
|
||||
manage(window) {
|
||||
@@ -128,7 +134,7 @@
|
||||
animate({
|
||||
window: window,
|
||||
duration: this.duration,
|
||||
- curve: QEasingCurve.OutExpo,
|
||||
+ curve: this.curve,
|
||||
animations: animations,
|
||||
});
|
||||
}
|
||||
diff -ruN a/package/contents/config/main.xml b/package/contents/config/main.xml
|
||||
--- a/package/contents/config/main.xml 2026-10-26 22:29:29
|
||||
+++ b/package/contents/config/main.xml 2026-10-26 22:29:29
|
||||
@@ -14,5 +14,8 @@
|
||||
<entry name="CrossFade" type="Bool">
|
||||
<default>false</default>
|
||||
</entry>
|
||||
+ <entry name="Curve" type="String">
|
||||
+ <default>OutExpo</default>
|
||||
+ </entry>
|
||||
</group>
|
||||
</kcfg>
|
||||
@@ -82,6 +82,13 @@ in
|
||||
fi
|
||||
echo "ok: the metadata says EnabledByDefault false"
|
||||
|
||||
# komorebi's patch: the curve is a setting (the stock effect names QEasingCurve.OutExpo too)
|
||||
grep -q -F 'readConfig("Curve"' "$main" ||
|
||||
fail "the script does not read a Curve setting: curve.patch is not in it"
|
||||
grep -q -F '<entry name="Curve"' "$effect/contents/config/main.xml" ||
|
||||
fail "the effect's settings have no Curve: curve.patch is not in it"
|
||||
echo "ok: the effect reads a Curve setting"
|
||||
|
||||
touch $out
|
||||
'';
|
||||
}
|
||||
@@ -23,6 +23,18 @@ def near(a: Color, b: Color, tolerance: int = 12) -> bool:
|
||||
return all(abs(x - y) <= tolerance for x, y in zip(a, b, strict=True))
|
||||
|
||||
|
||||
def leftmost(image: Image.Image, y: int, color: Color, tolerance: int = 12) -> int | None:
|
||||
"""Returns the `x` of the leftmost pixel of row `y` that is near `color`, or `None`.
|
||||
|
||||
A window that moves across the screen has its left edge where this finds the first pixel of its
|
||||
color, which is how a test sees how far along it is.
|
||||
"""
|
||||
for x in range(image.width):
|
||||
if near(pixel(image, x, y), color, tolerance):
|
||||
return x
|
||||
return None
|
||||
|
||||
|
||||
def ring(image: Image.Image, frame: Rect, color: Color, margin: int = 5) -> list[str]:
|
||||
"""Returns what is wrong with the ring around a window: a line for each side that has none.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from komorebi_vm import Rect
|
||||
from komorebi_vm.pixels import near, pixel, ring
|
||||
from komorebi_vm.pixels import leftmost, near, pixel, ring
|
||||
|
||||
BLUE = (66, 165, 245)
|
||||
GRAY = (128, 128, 128)
|
||||
@@ -63,3 +63,12 @@ def test_a_thin_border_is_not_found_further_out_than_it_is() -> None:
|
||||
|
||||
assert len(ring(image, frame, BLUE)) == 4
|
||||
assert ring(image, frame, BLUE, margin=2) == []
|
||||
|
||||
|
||||
def test_leftmost_is_where_a_row_first_has_the_color() -> None:
|
||||
image = Image.new("RGB", (100, 10), (0, 0, 0))
|
||||
ImageDraw.Draw(image).rectangle((30, 4, 60, 4), fill=BLUE)
|
||||
|
||||
assert leftmost(image, 4, BLUE) == 30
|
||||
assert leftmost(image, 5, BLUE) is None
|
||||
assert leftmost(image, 4, GRAY) is None
|
||||
@@ -333,6 +333,7 @@ border disable
|
||||
animation enable
|
||||
animation-duration 120
|
||||
animation-fps 30
|
||||
animation-style --style linear
|
||||
animation disable
|
||||
session-float-rule
|
||||
session-float-rules
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
# C border colors: every kind of window has its own: the focused window, the others, a locked
|
||||
# container that does not have the focus, a stack and a monocled window that have it, and a
|
||||
# floating window that has it
|
||||
# D animation curves: two curves put a window in different places at the same moment
|
||||
#
|
||||
# Every window is a `foot` of one color all over (`Kde.colored_window`), and a color is read at the
|
||||
# pixels just outside the frame of the window (`pixels.ring`). `komorebi/tests/maximize.rs` and
|
||||
@@ -19,6 +20,8 @@ import time
|
||||
from komorebi_vm import Checks, Kde, pixels
|
||||
|
||||
UNIT = "komorebi.service"
|
||||
# the daemon's log of the day, without colors, which every run of the unit adds to
|
||||
LOG = "/home/komorebi/.local/share/komorebi/komorebi_plaintext.log.*"
|
||||
ROUNDED_CORNERS = "kwin4_effect_shapecorners"
|
||||
|
||||
BLUE = (0, 0, 255)
|
||||
@@ -28,6 +31,7 @@ LOCKED = (158, 8, 8)
|
||||
STACK = (0, 165, 66)
|
||||
MONOCLE = (255, 51, 153)
|
||||
FLOATING = (245, 245, 165)
|
||||
RED = (255, 0, 0)
|
||||
|
||||
start_all()
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
@@ -65,11 +69,30 @@ def windows() -> None:
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
def ring_is(title: str, color: tuple[int, int, int]) -> bool:
|
||||
"""Returns true if and only if the window with this title has a ring of `color` just outside
|
||||
its frame, in a screenshot taken now."""
|
||||
def ring_wrong(title: str, color: tuple[int, int, int]) -> list[str]:
|
||||
"""What is wrong with the ring of `color` just outside the frame of the window with this title,
|
||||
in a screenshot taken now: a line for each side that has none."""
|
||||
wid = kde.wid(title)
|
||||
return wid != "" and pixels.ring(kde.shot(f"ring-{title}"), kde.rect(wid), color) == []
|
||||
if wid == "":
|
||||
return [f"there is no window titled {title}"]
|
||||
return pixels.ring(kde.shot(f"ring-{title}"), kde.rect(wid), color)
|
||||
|
||||
|
||||
def check_ring(description: str, title: str, color: tuple[int, int, int]) -> None:
|
||||
"""Waits for the window to have the ring, and says what is wrong when it does not."""
|
||||
ok = kde.wait_for(lambda: ring_wrong(title, color) == [], timeout=15)
|
||||
detail = ""
|
||||
if not ok:
|
||||
detail = f"\n active: {active_title()!r}, komorebi's focus: {kde.focused_title()!r}"
|
||||
detail += "".join(f"\n {w}" for w in ring_wrong(title, color))
|
||||
said = machine.execute(f"grep -h -i 'border effect\\|colour\\|effect' {LOG}")[1]
|
||||
detail += "".join(f"\n daemon: {line}" for line in said.splitlines()[-8:])
|
||||
checks.check(description + detail, ok)
|
||||
|
||||
|
||||
def active_title() -> str:
|
||||
wid = kde.active()
|
||||
return kde.title(wid) if wid else ""
|
||||
|
||||
|
||||
def focus(title: str) -> None:
|
||||
@@ -182,46 +205,74 @@ checks.check(
|
||||
)[0]
|
||||
== 0,
|
||||
)
|
||||
checks.check(
|
||||
"the focused window has the focus color",
|
||||
kde.wait_for(lambda: ring_is("blue", SINGLE), timeout=15),
|
||||
)
|
||||
checks.check("the others have the unfocused one", ring_is("green", UNFOCUSED))
|
||||
check_ring("the focused window has the focus color", "blue", SINGLE)
|
||||
check_ring("the others have the unfocused one", "green", UNFOCUSED)
|
||||
|
||||
# a locked container that does not have the focus
|
||||
focus("red")
|
||||
kde.komorebic("toggle-lock")
|
||||
focus("blue")
|
||||
checks.check(
|
||||
"a locked container that does not have the focus is marked",
|
||||
kde.wait_for(lambda: ring_is("red", LOCKED), timeout=15),
|
||||
)
|
||||
check_ring("a locked container that does not have the focus is marked", "red", LOCKED)
|
||||
focus("red")
|
||||
kde.komorebic("toggle-lock")
|
||||
focus("blue")
|
||||
|
||||
# a stack that has the focus: blue goes into the container on its left
|
||||
kde.komorebic("stack", "left")
|
||||
checks.check(
|
||||
"a stack with the focus has the stack color",
|
||||
kde.wait_for(lambda: ring_is("blue", STACK), timeout=15),
|
||||
)
|
||||
check_ring("a stack with the focus has the stack color", "blue", STACK)
|
||||
kde.komorebic("unstack")
|
||||
|
||||
# a monocled window
|
||||
kde.komorebic("toggle-monocle")
|
||||
checks.check(
|
||||
"a monocled window has the monocle color",
|
||||
kde.wait_for(lambda: ring_is("blue", MONOCLE), timeout=15),
|
||||
)
|
||||
check_ring("a monocled window has the monocle color", "blue", MONOCLE)
|
||||
kde.komorebic("toggle-monocle")
|
||||
|
||||
# a floating window that has the focus
|
||||
kde.komorebic("toggle-float")
|
||||
checks.check(
|
||||
"a floating window with the focus has the floating color",
|
||||
kde.wait_for(lambda: ring_is("blue", FLOATING), timeout=15),
|
||||
)
|
||||
check_ring("a floating window with the focus has the floating color", "blue", FLOATING)
|
||||
stop_komorebi()
|
||||
|
||||
print("== D. animation curves")
|
||||
# A 30 s animation, looked at a few seconds in: how far along the move is red, as seen on the
|
||||
# screen (the frames are already where they are going; only the picture is on its way). An ease out
|
||||
# is far along by then and a linear one has hardly started. Red is given the focus first so that
|
||||
# nothing hides its left edge, and the answer is a percentage of the way, so it does not depend on
|
||||
# how long the screenshot took.
|
||||
|
||||
|
||||
def progress(style: str) -> int:
|
||||
"""How far along, in percent, red is a few seconds into a flip of the layout with `style`."""
|
||||
start_komorebi()
|
||||
kde.komorebic("animation-duration", "30000")
|
||||
kde.komorebic("animation-style", "--style", style)
|
||||
kde.komorebic("animation", "enable")
|
||||
kde.colored_window("red", "ff0000")
|
||||
time.sleep(1)
|
||||
kde.colored_window("blue", "0000ff")
|
||||
time.sleep(20 * SCALE)
|
||||
focus("red")
|
||||
time.sleep(2)
|
||||
here = kde.rect(kde.wid("red"))
|
||||
row = here.y + here.h // 2
|
||||
from_x = pixels.leftmost(kde.shot(f"curve-before-{style}"), row, RED)
|
||||
kde.komorebic("flip-layout", "horizontal")
|
||||
kde.wait_for(lambda: kde.rect(kde.wid("red")) != here, timeout=10)
|
||||
to = kde.rect(kde.wid("red"))
|
||||
time.sleep(5 * SCALE)
|
||||
now_x = pixels.leftmost(kde.shot(f"curve-{style}"), row, RED)
|
||||
print(f" {style}: red's left edge on the screen went from {from_x} to {now_x}; its frame")
|
||||
print(f" goes from {here.x} to {to.x}")
|
||||
stop_komorebi()
|
||||
if from_x is None or now_x is None or to.x == here.x:
|
||||
return -1
|
||||
return (now_x - from_x) * 100 // (to.x - here.x)
|
||||
|
||||
|
||||
linear = progress("linear")
|
||||
expo = progress("ease-out-expo")
|
||||
print(f" a few seconds into a 30 s move, red is this far along: {linear}% with Linear,")
|
||||
print(f" {expo}% with EaseOutExpo")
|
||||
checks.check("Linear is less than 60% of the way", 0 <= linear < 60)
|
||||
checks.check("EaseOutExpo is at least 20 points further along than Linear", expo >= linear + 20)
|
||||
|
||||
checks.finish()
|
||||
@@ -196,6 +196,9 @@ def point_in(frame: Rect) -> tuple[int, int]:
|
||||
print("== C. komorebi runs a 30 s animation")
|
||||
start_komorebi()
|
||||
kde.komorebic("animation-duration", "30000")
|
||||
# an ease out is at 97 % after half of its time, which the waits below rely on (the default style
|
||||
# is linear, which is at half)
|
||||
kde.komorebic("animation-style", "--style", "ease-out-expo")
|
||||
kde.komorebic("animation", "enable")
|
||||
checks.check(
|
||||
"the animation effect is loaded",
|
||||
|
||||
+227
-2
@@ -329,6 +329,200 @@
|
||||
}
|
||||
},
|
||||
"$defs": {
|
||||
"AnimationStyle": {
|
||||
"description": "Mathematical function which describes the rate at which a value changes",
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "Linear",
|
||||
"type": "string",
|
||||
"const": "Linear"
|
||||
},
|
||||
{
|
||||
"description": "Ease in sine",
|
||||
"type": "string",
|
||||
"const": "EaseInSine"
|
||||
},
|
||||
{
|
||||
"description": "Ease out sine",
|
||||
"type": "string",
|
||||
"const": "EaseOutSine"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out sine",
|
||||
"type": "string",
|
||||
"const": "EaseInOutSine"
|
||||
},
|
||||
{
|
||||
"description": "Ease in quad",
|
||||
"type": "string",
|
||||
"const": "EaseInQuad"
|
||||
},
|
||||
{
|
||||
"description": "Ease out quad",
|
||||
"type": "string",
|
||||
"const": "EaseOutQuad"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out quad",
|
||||
"type": "string",
|
||||
"const": "EaseInOutQuad"
|
||||
},
|
||||
{
|
||||
"description": "Ease in cubic",
|
||||
"type": "string",
|
||||
"const": "EaseInCubic"
|
||||
},
|
||||
{
|
||||
"description": "Ease out cubic",
|
||||
"type": "string",
|
||||
"const": "EaseOutCubic"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out cubic",
|
||||
"type": "string",
|
||||
"const": "EaseInOutCubic"
|
||||
},
|
||||
{
|
||||
"description": "Ease in quart",
|
||||
"type": "string",
|
||||
"const": "EaseInQuart"
|
||||
},
|
||||
{
|
||||
"description": "Ease out quart",
|
||||
"type": "string",
|
||||
"const": "EaseOutQuart"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out quart",
|
||||
"type": "string",
|
||||
"const": "EaseInOutQuart"
|
||||
},
|
||||
{
|
||||
"description": "Ease in quint",
|
||||
"type": "string",
|
||||
"const": "EaseInQuint"
|
||||
},
|
||||
{
|
||||
"description": "Ease out quint",
|
||||
"type": "string",
|
||||
"const": "EaseOutQuint"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out quint",
|
||||
"type": "string",
|
||||
"const": "EaseInOutQuint"
|
||||
},
|
||||
{
|
||||
"description": "Ease in expo",
|
||||
"type": "string",
|
||||
"const": "EaseInExpo"
|
||||
},
|
||||
{
|
||||
"description": "Ease out expo",
|
||||
"type": "string",
|
||||
"const": "EaseOutExpo"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out expo",
|
||||
"type": "string",
|
||||
"const": "EaseInOutExpo"
|
||||
},
|
||||
{
|
||||
"description": "Ease in circ",
|
||||
"type": "string",
|
||||
"const": "EaseInCirc"
|
||||
},
|
||||
{
|
||||
"description": "Ease out circ",
|
||||
"type": "string",
|
||||
"const": "EaseOutCirc"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out circ",
|
||||
"type": "string",
|
||||
"const": "EaseInOutCirc"
|
||||
},
|
||||
{
|
||||
"description": "Ease in back",
|
||||
"type": "string",
|
||||
"const": "EaseInBack"
|
||||
},
|
||||
{
|
||||
"description": "Ease out back",
|
||||
"type": "string",
|
||||
"const": "EaseOutBack"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out back",
|
||||
"type": "string",
|
||||
"const": "EaseInOutBack"
|
||||
},
|
||||
{
|
||||
"description": "Ease in elastic",
|
||||
"type": "string",
|
||||
"const": "EaseInElastic"
|
||||
},
|
||||
{
|
||||
"description": "Ease out elastic",
|
||||
"type": "string",
|
||||
"const": "EaseOutElastic"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out elastic",
|
||||
"type": "string",
|
||||
"const": "EaseInOutElastic"
|
||||
},
|
||||
{
|
||||
"description": "Ease in bounce",
|
||||
"type": "string",
|
||||
"const": "EaseInBounce"
|
||||
},
|
||||
{
|
||||
"description": "Ease out bounce",
|
||||
"type": "string",
|
||||
"const": "EaseOutBounce"
|
||||
},
|
||||
{
|
||||
"description": "Ease in out bounce",
|
||||
"type": "string",
|
||||
"const": "EaseInOutBounce"
|
||||
},
|
||||
{
|
||||
"title": "CubicBezier",
|
||||
"description": "Custom Cubic Bézier function",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"CubicBezier": {
|
||||
"type": "array",
|
||||
"maxItems": 4,
|
||||
"minItems": 4,
|
||||
"prefixItems": [
|
||||
{
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"CubicBezier"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"AnimationsConfig": {
|
||||
"description": "Animation configuration",
|
||||
"type": "object",
|
||||
@@ -359,6 +553,18 @@
|
||||
"format": "uint64",
|
||||
"default": 60,
|
||||
"minimum": 0
|
||||
},
|
||||
"style": {
|
||||
"description": "Set the animation style",
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/$defs/PerAnimationPrefixConfig3"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": "Linear"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -881,7 +1087,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"PerAnimationPrefixConfig": {
|
||||
"description": "Animation configuration\n\nThis can be either global:\n```json\n{\n \"enabled\": true,\n \"fps\": 60,\n \"duration\": 250\n}\n```\n\nOr scoped by an animation kind prefix:\n```json\n{\n \"movement\": {\n \"enabled\": true,\n \"fps\": 60,\n \"duration\": 250\n }\n}\n```",
|
||||
"description": "Animation configuration\n\nThis can be either global:\n```json\n{\n \"enabled\": true,\n \"style\": \"EaseInSine\",\n \"fps\": 60,\n \"duration\": 250\n}\n```\n\nOr scoped by an animation kind prefix:\n```json\n{\n \"movement\": {\n \"enabled\": true,\n \"style\": \"EaseInSine\",\n \"fps\": 60,\n \"duration\": 250\n }\n}\n```",
|
||||
"anyOf": [
|
||||
{
|
||||
"description": "Animation configuration prefixed for a specific animation kind",
|
||||
@@ -900,7 +1106,7 @@
|
||||
]
|
||||
},
|
||||
"PerAnimationPrefixConfig2": {
|
||||
"description": "Animation configuration\n\nThis can be either global:\n```json\n{\n \"enabled\": true,\n \"fps\": 60,\n \"duration\": 250\n}\n```\n\nOr scoped by an animation kind prefix:\n```json\n{\n \"movement\": {\n \"enabled\": true,\n \"fps\": 60,\n \"duration\": 250\n }\n}\n```",
|
||||
"description": "Animation configuration\n\nThis can be either global:\n```json\n{\n \"enabled\": true,\n \"style\": \"EaseInSine\",\n \"fps\": 60,\n \"duration\": 250\n}\n```\n\nOr scoped by an animation kind prefix:\n```json\n{\n \"movement\": {\n \"enabled\": true,\n \"style\": \"EaseInSine\",\n \"fps\": 60,\n \"duration\": 250\n }\n}\n```",
|
||||
"anyOf": [
|
||||
{
|
||||
"description": "Animation configuration prefixed for a specific animation kind",
|
||||
@@ -922,6 +1128,25 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"PerAnimationPrefixConfig3": {
|
||||
"description": "Animation configuration\n\nThis can be either global:\n```json\n{\n \"enabled\": true,\n \"style\": \"EaseInSine\",\n \"fps\": 60,\n \"duration\": 250\n}\n```\n\nOr scoped by an animation kind prefix:\n```json\n{\n \"movement\": {\n \"enabled\": true,\n \"style\": \"EaseInSine\",\n \"fps\": 60,\n \"duration\": 250\n }\n}\n```",
|
||||
"anyOf": [
|
||||
{
|
||||
"description": "Animation configuration prefixed for a specific animation kind",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"movement": {
|
||||
"$ref": "#/$defs/AnimationStyle"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"description": "Animation configuration for all animation kinds",
|
||||
"$ref": "#/$defs/AnimationStyle"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Placement": {
|
||||
"description": "Placement behavior for floating windows",
|
||||
"oneOf": [
|
||||
|
||||
Reference in new issue
Block a user