mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-12-04 14:06:32 +01:00
komorebi draws no border. KWin's KDE Rounded Corners effect does, outside each window in the gap the layout leaves, and komorebi says how it looks. The window manager describes a Look (a border with a width, a radius and two colors) and asks the backend for it with Backend::apply_look after every event, message and retile. The backend answers whether borders are being drawn, and the layout leaves room around the windows only while they are: a border with no effect to draw it takes none. The KWin backend writes the effect's settings into the user's kwinrc, with every inner outline off (the effect's default draws one over the title bar), loads the effect when borders are on and has it read them again. It unloads the effect and puts the user's settings back when the borders go or komorebi exits. The module installs the effect (effects.borders), which is built to stay unloaded until komorebi asks, and vm-look reads the pixels around two windows in a real session. The session library of the VM tests also waits for the panel of the Plasma shell now: a window komorebi tiles before the panel is made is tiled under it, which hides the bottom of its border from a screenshot. Kde.wait_for_panel_room waits until the daemon's work area is not the whole of its monitor, which is the daemon having learned that the panel takes room, and vm-look calls it where the daemon starts, before the windows open. The shell makes its panel and KWin takes room for it a while later, which the daemon learns of up to a second after, so a daemon that tiles in between puts the windows under the panel and tiles them again, and a screenshot taken between the two shows frames as high as the screen. It is a wait and not a check, since a session that is too slow, as TCG often is, may never take the room. komorebic gets border, border-width and border-offset, and visible-windows. komorebi.json takes the same settings as border, border_width and border_offset, and border_radius, which has no command. The module warns when config asks for borders and the effect is not installed.
341 lines
13 KiB
Nix
341 lines
13 KiB
Nix
# `services.komorebi`: komorebi in the Plasma session of every user of a NixOS machine. The flake
|
|
# exports this module as `nixosModules.default` and `nixosModules.komorebi`, together with its
|
|
# overlay, which provides `pkgs.komorebi-full` (see docs/installation.md). What the module
|
|
# guarantees, and what enforces each guarantee, is in docs/dev/ARCHITECTURE.md; its tests are
|
|
# nix/tests/nixos-module.nix and the VM suite `module`.
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.komorebi;
|
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
# The options `just nixgen` makes from `schema.json`, which type `config`
|
|
komorebiOptionsModule = import ./komorebi-options.nix { inherit lib; };
|
|
|
|
# the Nix module system uses null for an optional field that is not set, and the schema wants
|
|
# the field to be absent
|
|
filterNulls =
|
|
value:
|
|
if value == null then
|
|
null
|
|
else if builtins.isList value then
|
|
map filterNulls (builtins.filter (x: x != null) value)
|
|
else if builtins.isAttrs value then
|
|
lib.filterAttrs (_n: v: v != null) (builtins.mapAttrs (_n: v: filterNulls v) value)
|
|
else
|
|
value;
|
|
|
|
# A komorebi.json, checked against the schema the Rust types make (`schema.json`). Comment
|
|
# lines are taken out first: komorebi reads JSON with comments, and the schema checker does not.
|
|
validateJsonFile =
|
|
{
|
|
name,
|
|
jsonFile,
|
|
}:
|
|
pkgs.runCommand "validated-${name}" { nativeBuildInputs = [ pkgs.check-jsonschema ]; } ''
|
|
grep -v '^\s*//' ${jsonFile} > clean.json
|
|
check-jsonschema --schemafile ${../schema.json} clean.json
|
|
cp clean.json $out
|
|
'';
|
|
|
|
fetchAppSpecificSource =
|
|
source:
|
|
pkgs.fetchurl {
|
|
url = "https://raw.githubusercontent.com/${source.owner}/${source.repo}/${source.rev}/${source.path}";
|
|
inherit (source) hash;
|
|
};
|
|
|
|
applicationSpecificConfigFiles = map fetchAppSpecificSource cfg.applicationSpecificConfiguration.sources;
|
|
|
|
# one file is a path, several are a list of paths
|
|
appSpecificPaths =
|
|
if builtins.length applicationSpecificConfigFiles == 1 then
|
|
"${builtins.head applicationSpecificConfigFiles}"
|
|
else
|
|
map (f: "${f}") applicationSpecificConfigFiles;
|
|
|
|
shouldUseAppSpecific =
|
|
cfg.applicationSpecificConfiguration.enable && applicationSpecificConfigFiles != [ ];
|
|
|
|
# What `config` and `applicationSpecificConfiguration` make: the komorebi.json as an attribute
|
|
# set, with no null in it, or null when there is nothing to write
|
|
configAttrs =
|
|
if cfg.config == null && !shouldUseAppSpecific then
|
|
null
|
|
else
|
|
filterNulls (
|
|
(if cfg.config == null then { } else cfg.config)
|
|
// lib.optionalAttrs shouldUseAppSpecific { app_specific_configuration_path = appSpecificPaths; }
|
|
);
|
|
|
|
# the file the daemon is given: the one `configFile` names, or the one the options make, each
|
|
# checked against the schema
|
|
komorebiConfigFile =
|
|
if cfg.configFile != null then
|
|
validateJsonFile {
|
|
name = "komorebi.json";
|
|
jsonFile = cfg.configFile;
|
|
}
|
|
else if configAttrs != null then
|
|
validateJsonFile {
|
|
name = "komorebi.json";
|
|
jsonFile = jsonFormat.generate "komorebi.json" configAttrs;
|
|
}
|
|
else
|
|
null;
|
|
in
|
|
{
|
|
options.services.komorebi = {
|
|
enable = lib.mkEnableOption "komorebi, the tiling window manager, in the Plasma session of every user";
|
|
|
|
package = lib.mkPackageOption pkgs "komorebi-full" {
|
|
extraDescription = ''
|
|
It must have `bin/komorebi`, which the unit runs, and `bin/komorebic`. The module installs
|
|
both in the system profile.
|
|
'';
|
|
};
|
|
|
|
logLevel = lib.mkOption {
|
|
type = lib.types.enum [
|
|
"error"
|
|
"warn"
|
|
"info"
|
|
"debug"
|
|
"trace"
|
|
];
|
|
default = "info";
|
|
description = ''
|
|
How much the daemon logs: its `--log-level`. The log goes to the journal of the unit
|
|
(`journalctl --user -u komorebi`) and to the daemon's log files, which `komorebic log`
|
|
follows.
|
|
'';
|
|
};
|
|
|
|
configFile = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.path;
|
|
default = null;
|
|
example = lib.literalExpression "./komorebi.json";
|
|
description = ''
|
|
The `komorebi.json` the daemon is configured by, checked against the schema of
|
|
`komorebi.json` when the system is built. The unit starts komorebi with it, as `--config`,
|
|
in place of the `komorebi.json` the daemon looks for in `~/.config/komorebi`
|
|
(`$KOMOREBI_CONFIG_HOME`). The file is in the Nix store, so it does not change under the
|
|
daemon: a new file is read when the daemon starts again. `komorebic configuration` still
|
|
shows the file of the config home, which the daemon does not read while this is set. With
|
|
neither `configFile` nor `config`, the daemon reads the file of the config home, if there
|
|
is one. Ignored by `config`, which is ignored when this is set.
|
|
'';
|
|
};
|
|
|
|
config = lib.mkOption {
|
|
type = lib.types.nullOr komorebiOptionsModule.options.komorebi.type;
|
|
default = null;
|
|
example = lib.literalExpression ''
|
|
{
|
|
default_workspace_padding = 15;
|
|
monitors = [
|
|
{
|
|
workspaces = [
|
|
{ name = "web"; layout = "BSP"; }
|
|
{ name = "code"; layout = "Columns"; }
|
|
];
|
|
}
|
|
];
|
|
}
|
|
'';
|
|
description = ''
|
|
The configuration of komorebi, written as Nix: every key of `komorebi.json`, typed from
|
|
the schema, so a layout that does not exist or a value of the wrong kind does not
|
|
evaluate. The module writes it as a `komorebi.json`, checks that against the schema, and
|
|
starts komorebi with it as `--config`. Ignored if `configFile` is set. A key you leave
|
|
out is the default the schema gives it, if it gives one, and the daemon's own otherwise.
|
|
'';
|
|
};
|
|
|
|
applicationSpecificConfiguration = {
|
|
enable = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = true;
|
|
description = "Whether to use the sources of application specific configuration.";
|
|
};
|
|
|
|
sources = lib.mkOption {
|
|
type = lib.types.listOf (
|
|
lib.types.submodule {
|
|
options = {
|
|
owner = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "GitHub repository owner.";
|
|
example = "LGUG2Z";
|
|
};
|
|
repo = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "GitHub repository name.";
|
|
example = "komorebi-application-specific-configuration";
|
|
};
|
|
rev = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "Git revision (commit hash, tag, or branch).";
|
|
example = "09ebdcd95780b168cecde2f2d49096a58e91365f";
|
|
};
|
|
path = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "applications.json";
|
|
description = "Path to the JSON file within the repository.";
|
|
};
|
|
hash = lib.mkOption {
|
|
type = lib.types.str;
|
|
description = "SHA256 hash of the file, for reproducibility.";
|
|
example = "sha256-gfYubJpVEU6vxdd/vqujQhQX8mdAEE9ImugqdIyTQKk=";
|
|
};
|
|
};
|
|
}
|
|
);
|
|
default = [ ];
|
|
description = ''
|
|
Files of application specific configuration, each fetched from GitHub, which the module
|
|
gives the daemon as `app_specific_configuration_path` of the configuration it writes
|
|
(it replaces the value `config` has for that key). There are none by default: no
|
|
community file for KDE Plasma is known. Ignored when `configFile` is set.
|
|
'';
|
|
example = lib.literalExpression ''
|
|
[
|
|
{
|
|
owner = "myuser";
|
|
repo = "my-komorebi-rules";
|
|
rev = "0123456789abcdef0123456789abcdef01234567";
|
|
path = "applications.json";
|
|
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
|
}
|
|
]
|
|
'';
|
|
};
|
|
};
|
|
|
|
effects.borders = {
|
|
enable = lib.mkOption {
|
|
type = lib.types.bool;
|
|
default = true;
|
|
description = ''
|
|
Install the KWin effect that draws komorebi's borders, KDE Rounded Corners. This is
|
|
installation only: whether borders are drawn is komorebi's setting (`komorebic border`),
|
|
which asks KWin to load the effect when it is on. KWin finds effects when it starts, so
|
|
an effect installed by a switch to a new system is found after the next login.
|
|
|
|
Without the effect, komorebi draws no border and leaves no room for one.
|
|
'';
|
|
};
|
|
|
|
package = lib.mkPackageOption pkgs "kde-rounded-corners-komorebi" {
|
|
extraDescription = ''
|
|
It must have `lib/qt-6/plugins/kwin/effects/plugins/kwin4_effect_shapecorners.so`, built
|
|
against the KWin of the system and not loaded by default. The default is KDE Rounded
|
|
Corners 0.11.0, which draws correctly on KWin 6.8.
|
|
'';
|
|
};
|
|
};
|
|
|
|
internal.configAttrs = lib.mkOption {
|
|
type = lib.types.nullOr lib.types.attrs;
|
|
readOnly = true;
|
|
internal = true;
|
|
description = ''
|
|
What `config` and `applicationSpecificConfiguration` make, before it is written as JSON:
|
|
the `komorebi.json` as an attribute set with no null in it, or null when neither is set.
|
|
The tests of the module read it, so that they need not build the file.
|
|
'';
|
|
};
|
|
|
|
execStart = lib.mkOption {
|
|
type = lib.types.str;
|
|
readOnly = true;
|
|
description = ''
|
|
The command line the unit starts komorebi with: `bin/komorebi` of `package`, with
|
|
`logLevel`, and with `--config` and the checked `komorebi.json` when `configFile` or
|
|
`config` is set. The module sets it, and setting it anywhere else is an error. A unit of your own that runs komorebi somewhere
|
|
else, as the VM tests do in their headless sessions, starts it with this, the way the
|
|
module does.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = lib.mkMerge [
|
|
{
|
|
services.komorebi.execStart = lib.concatStringsSep " " (
|
|
[
|
|
(lib.getExe' cfg.package "komorebi")
|
|
"--log-level"
|
|
cfg.logLevel
|
|
]
|
|
++ lib.optionals (komorebiConfigFile != null) [
|
|
"--config"
|
|
"${komorebiConfigFile}"
|
|
]
|
|
);
|
|
services.komorebi.internal.configAttrs = configAttrs;
|
|
}
|
|
|
|
(lib.mkIf cfg.enable {
|
|
assertions = [
|
|
{
|
|
assertion = config.services.desktopManager.plasma6.enable;
|
|
message = ''
|
|
services.komorebi needs Plasma 6: komorebi runs in a Plasma Wayland session, and the
|
|
session starts it. Set services.desktopManager.plasma6.enable = true.
|
|
'';
|
|
}
|
|
];
|
|
|
|
warnings =
|
|
lib.optional (
|
|
cfg.configFile != null && cfg.config != null
|
|
) "services.komorebi.config is ignored: services.komorebi.configFile is set."
|
|
++
|
|
lib.optional (cfg.configFile != null && cfg.applicationSpecificConfiguration.sources != [ ])
|
|
"services.komorebi.applicationSpecificConfiguration is ignored: services.komorebi.configFile is set."
|
|
++
|
|
lib.optional
|
|
(
|
|
cfg.configFile == null
|
|
&& cfg.config != null
|
|
&& (cfg.config.border or null) == true
|
|
&& !cfg.effects.borders.enable
|
|
)
|
|
"services.komorebi.config sets border to true, but services.komorebi.effects.borders.enable is false: without the effect, komorebi draws no border.";
|
|
|
|
environment.systemPackages = [
|
|
cfg.package
|
|
]
|
|
++ lib.optional cfg.effects.borders.enable cfg.effects.borders.package;
|
|
|
|
# A user unit, so it runs for every user who logs in to Plasma. plasma-workspace.target is
|
|
# the target of a Plasma session's services, and plasma-core.target, which it requires, is
|
|
# ordered after KWin's service: the daemon exits when KWin is not on the session bus.
|
|
systemd.user.services.komorebi = {
|
|
description = "komorebi, the tiling window manager";
|
|
wantedBy = [ "plasma-workspace.target" ];
|
|
after = [ "plasma-core.target" ];
|
|
# NixOS gives a unit a PATH made of a few store paths; this is the PATH a terminal in the
|
|
# user's session has
|
|
enableDefaultPath = false;
|
|
environment.PATH = lib.concatStringsSep ":" [
|
|
"/run/wrappers/bin"
|
|
"/etc/profiles/per-user/%u/bin"
|
|
"/run/current-system/sw/bin"
|
|
];
|
|
serviceConfig = {
|
|
ExecStart = cfg.execStart;
|
|
Restart = "on-failure";
|
|
# what komorebi exits with when it is stopped with SIGTERM, as systemd stops a unit
|
|
SuccessExitStatus = 130;
|
|
};
|
|
};
|
|
})
|
|
];
|
|
}
|