From 97d183e2e466808f5d7cd1c838815bedd88f37fe Mon Sep 17 00:00:00 2001 From: dawidsowa Date: Mon, 5 Jul 2021 22:29:34 +0200 Subject: [PATCH] devilspie2: add module (#1477) Co-authored-by: Sumner Evans Co-authored-by: Nicolas Berbiche --- .github/CODEOWNERS | 3 ++ modules/modules.nix | 1 + modules/services/devilspie2.nix | 42 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/services/devilspie2/config.lua | 11 +++++ .../services/devilspie2/configuration.nix | 39 +++++++++++++++++ tests/modules/services/devilspie2/default.nix | 1 + 7 files changed, 98 insertions(+) create mode 100644 modules/services/devilspie2.nix create mode 100644 tests/modules/services/devilspie2/config.lua create mode 100644 tests/modules/services/devilspie2/configuration.nix create mode 100644 tests/modules/services/devilspie2/default.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f7deb577..c0d30b53 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -214,6 +214,9 @@ /modules/services/clipmenu.nix @DamienCassou +/modules/services/devilspie2.nix @dawidsowa +/tests/modules/services/devilspie2 @dawidsowa + /modules/services/dropbox.nix @eyJhb /tests/modules/services/dropbox @eyJhb diff --git a/modules/modules.nix b/modules/modules.nix index 6d6cff5d..3609f8fe 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -159,6 +159,7 @@ let (loadModule ./services/cbatticon.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/clipmenu.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/compton.nix { }) + (loadModule ./services/devilspie2.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/dropbox.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/dunst.nix { }) (loadModule ./services/dwm-status.nix { condition = hostPlatform.isLinux; }) diff --git a/modules/services/devilspie2.nix b/modules/services/devilspie2.nix new file mode 100644 index 00000000..4b93217c --- /dev/null +++ b/modules/services/devilspie2.nix @@ -0,0 +1,42 @@ +{ config, lib, pkgs, ... }: + +with lib; +let cfg = config.services.devilspie2; +in { + meta.maintainers = [ maintainers.dawidsowa ]; + + options = { + services.devilspie2 = { + enable = mkEnableOption '' + Devilspie2, a window matching utility, allowing the user to + perform scripted actions on windows as they are created''; + + config = mkOption { + type = types.lines; + default = ""; + description = '' + Content of file placed in the devilspie2 config directory. + ''; + example = '' + if (get_window_class() == "Gnome-terminal") then + make_always_on_top(); + end + ''; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services.devilspie2 = { + Service.ExecStart = "${pkgs.devilspie2}/bin/devilspie2"; + Unit = { + Description = "devilspie2"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Install.WantedBy = [ "graphical-session.target" ]; + }; + + xdg.configFile."devilspie2/config.lua".text = cfg.config; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 130eab4c..b5f69723 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -114,6 +114,7 @@ import nmt { ./modules/programs/waybar ./modules/programs/xmobar ./modules/services/barrier + ./modules/services/devilspie2 ./modules/services/dropbox ./modules/services/emacs ./modules/services/fluidsynth diff --git a/tests/modules/services/devilspie2/config.lua b/tests/modules/services/devilspie2/config.lua new file mode 100644 index 00000000..3024d3c3 --- /dev/null +++ b/tests/modules/services/devilspie2/config.lua @@ -0,0 +1,11 @@ +if (get_window_class() == "Gnome-terminal") then + make_always_on_top(); +end + +if string.match(get_window_name(), "LibreOffice Writer") then + maximize(); +end + +if (get_window_class()=="Org.gnome.Nautilus") then + set_window_geometry(1600,300,900,700); +end diff --git a/tests/modules/services/devilspie2/configuration.nix b/tests/modules/services/devilspie2/configuration.nix new file mode 100644 index 00000000..eb576b9f --- /dev/null +++ b/tests/modules/services/devilspie2/configuration.nix @@ -0,0 +1,39 @@ +{ config, pkgs, ... }: { + config = { + services.devilspie2 = { + enable = true; + + config = '' + if (get_window_class() == "Gnome-terminal") then + make_always_on_top(); + end + + if string.match(get_window_name(), "LibreOffice Writer") then + maximize(); + end + + if (get_window_class()=="Org.gnome.Nautilus") then + set_window_geometry(1600,300,900,700); + end + ''; + }; + + nixpkgs.overlays = [ + (self: super: { devilspie2 = pkgs.writeScriptBin "dummy-devilspie2" ""; }) + ]; + + nmt.script = '' + configlua=home-files/.config/devilspie2/config.lua + + assertFileExists $configlua + + assertFileContent $configlua ${./config.lua} + + serviceFile=home-files/.config/systemd/user/devilspie2.service + + assertFileExists $serviceFile + + assertFileRegex $serviceFile 'ExecStart=.*/bin/devilspie2' + ''; + }; +} diff --git a/tests/modules/services/devilspie2/default.nix b/tests/modules/services/devilspie2/default.nix new file mode 100644 index 00000000..b62380ee --- /dev/null +++ b/tests/modules/services/devilspie2/default.nix @@ -0,0 +1 @@ +{ devilspie2-configuration = ./configuration.nix; }