Files
nixos/modules/home/sway/kanshi.nix
2025-09-09 17:34:58 +02:00

229 lines
6.9 KiB
Nix

{
lib,
config,
pkgs,
...
}: let
cfg = config.myConfig.sway.kanshi;
in {
options.myConfig.sway.kanshi = {
enable = lib.mkEnableOption "kanshi, a dynamic display recognizer";
laptop = lib.mkEnableOption "laptop workspaces";
};
config = lib.mkIf cfg.enable {
services.kanshi = let
bgdir = ../../../assets;
bg1080 = bgdir + "/bg1080.png";
bg1080vert = bgdir + "/bg1080vert.png";
bg4k = bgdir + "/bg4k.png";
sway_commands = commands: "${pkgs.sway}/bin/swaymsg '${lib.strings.concatStringsSep ", " commands}'";
workspace = workspace: monitor: [
''workspace "${workspace}" output "${monitor}"''
''workspace --no-auto-back-and-forth ${workspace}''
''move workspace to "${monitor}"''
];
luhbots_workstation = settings: {
profile.outputs = [
{
criteria = "eDP-1";
position =
if settings.vertical.left
then "1080,1080"
else "0,1080";
}
{
criteria = settings.horizontal.name;
position =
if settings.vertical.left
then "1080,0"
else "0,0";
}
{
criteria = settings.vertical.name;
transform = settings.vertical.orientation;
position =
if settings.vertical.left
then "0,0"
else "1920,0";
}
];
profile.exec = [
(sway_commands (
[
"output eDP-1 bg ${bg1080} fit"
"output \"${settings.horizontal.name}\" bg ${bg4k} fit"
"output \"${settings.vertical.name}\" bg ${bg1080vert} fit"
]
++ (workspace "obsidian" settings.horizontal.name)
++ (workspace "5" settings.horizontal.name)
++ (workspace "music" "eDP-1")
++ (workspace "msg" "eDP-1")
++ (workspace "term" settings.vertical.name)
++ (workspace "main" settings.horizontal.name)
))
];
};
in {
enable = true;
settings = lib.mkIf cfg.laptop [
{
profile.name = "laptop";
profile.outputs = [
{
criteria = "eDP-1";
position = "0,0";
}
];
}
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL U2422HE GRCPH83";
vertical = {
name = "NEC Corporation E243WMi 7X313185NB";
left = false;
orientation = "90";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL U2422HE 8YCPH83";
vertical = {
name = "Dell Inc. DELL P2422HE 28XL9M3";
left = false;
orientation = "normal";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL U2422HE 53DCH83";
vertical = {
name = "Dell Inc. DELL U2412M 0FFXD46I4U5S";
left = false;
orientation = "90";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL P2422HE 4BXL9M";
vertical = {
name = "NEC Corporation E243WMi 75309334NB";
left = true;
orientation = "90";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL P2422HE JLXL9M3";
vertical = {
name = "NEC Corporation E243WMi 59118576NB";
left = true;
orientation = "90";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL P2422HE 7VWL9M3";
vertical = {
name = "ViewSonic Corporation VG2448 V5E201960167";
left = false;
orientation = "90";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL U2422HE 7HCPH83";
vertical = {
name = "Dell Inc. DELL U2422HE 1XFFH83";
left = true;
orientation = "90";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL U2422HE 5XY5H83";
vertical = {
name = "Dell Inc. DELL U2419H 11B7Y13";
left = true;
orientation = "270";
};
})
(luhbots_workstation {
horizontal.name = "Dell Inc. DELL P2422HE 4BXL9M3";
vertical = {
name = "NEC Corporation E243WMi 75309334NB";
left = true;
orientation = "90";
};
})
{
profile.name = "docked-4k";
profile.outputs = [
{
criteria = "eDP-1";
position = "320,1440";
}
{
criteria = "HannStar Display Corp HC281UPB ";
position = "0,0";
mode = "3840x2160@60";
scale = 1.5;
}
];
profile.exec = [
(sway_commands
(
(workspace "obsidian" "HDMI-A-1")
++ (workspace "5" "HDMI-A-1")
++ (workspace "music" "eDP-1")
++ (workspace "msg" "eDP-1")
++ (workspace "term" "eDP-1")
++ (workspace "main" "HDMI-A-1")
))
];
}
{
profile.outputs = [
{
criteria = "eDP-1";
position = "0,0";
}
{
criteria = "Hisense Electric Co., Ltd. HISENSE 0x00000001";
position = "1920,0";
}
];
profile.exec = [
(sway_commands
(
(workspace "mirror" "HDMI-A-1")
++ ["exec ${pkgs.wl-mirror}/bin/wl-present mirror eDP-1 --fullscreen-output HDMI-A-1 --fullscreen"]
++ (workspace "obsidian" "eDP-1")
++ (workspace "5" "eDP-1")
++ (workspace "music" "eDP-1")
++ (workspace "msg" "eDP-1")
++ (workspace "term" "eDP-1")
++ (workspace "main" "eDP-1")
))
];
}
{
profile.outputs = [
{
criteria = "eDP-1";
position = "0,1080";
}
{
criteria = "ViewSonic Corporation VG2448 V5E201864188";
position = "0,0";
}
];
profile.exec = [
(sway_commands
(
(workspace "obsidian" "ViewSonic Corporation VG2448 V5E201864188")
++ (workspace "5" "ViewSonic Corporation VG2448 V5E201864188")
++ (workspace "music" "eDP-1")
++ (workspace "msg" "eDP-1")
++ (workspace "term" "eDP-1")
++ (workspace "main" "ViewSonic Corporation VG2448 V5E201864188")
))
];
}
];
};
};
}