From 19ebab97e818256bf4d751c119a1e189d6d0f075 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Wed, 28 Apr 2021 13:52:31 -0600 Subject: [PATCH] i3, sway: extract border functionality to common function (#1947) * i3, sway: extract border functionality to common function Converted the i3 module to use default_border and default_floating_border and extracted that functionality out to be shared between the i3 and sway modules. * i3: add sumnerevans as maintainer --- .github/CODEOWNERS | 6 ++++++ modules/services/window-managers/i3-sway/i3.nix | 11 ++++------- .../window-managers/i3-sway/lib/functions.nix | 9 +++++++++ modules/services/window-managers/i3-sway/sway.nix | 9 ++------- .../window-managers/i3/i3-followmouse-expected.conf | 4 ++-- .../window-managers/i3/i3-keybindings-expected.conf | 4 ++-- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 96edbaf04..1cccfe71a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -250,7 +250,13 @@ /modules/services/unison.nix @pacien +/modules/services/window-managers/i3-sway/i3.nix @sumnerevans +/tests/modules/services/window-managers/i3 @sumnerevans + +/modules/services/window-managers/i3-sway/lib @sumnerevans + /modules/services/window-managers/i3-sway/sway.nix @alexarice @sumnerevans +/tests/modules/services/window-managers/sway @sumnerevans /modules/services/wlsunset.nix @matrss /tests/modules/services/wlsunset @matrss diff --git a/modules/services/window-managers/i3-sway/i3.nix b/modules/services/window-managers/i3-sway/i3.nix index 37f6e8bd8..35efee454 100644 --- a/modules/services/window-managers/i3-sway/i3.nix +++ b/modules/services/window-managers/i3-sway/i3.nix @@ -140,7 +140,7 @@ let inherit (commonFunctions) keybindingsStr keycodebindingsStr modeStr assignStr barStr gapsStr - floatingCriteriaStr windowCommandsStr colorSetStr; + floatingCriteriaStr windowCommandsStr colorSetStr windowBorderString; startupEntryStr = { command, always, notification, workspace, ... }: '' ${if always then "exec_always" else "exec"} ${ @@ -157,12 +157,7 @@ let with cfg.config; '' font pango:${concatStringsSep ", " fonts} floating_modifier ${floating.modifier} - new_window ${if window.titlebar then "normal" else "pixel"} ${ - toString window.border - } - new_float ${if floating.titlebar then "normal" else "pixel"} ${ - toString floating.border - } + ${windowBorderString window floating} hide_edge_borders ${window.hideEdgeBorders} force_focus_wrapping ${if focus.forceWrapping then "yes" else "no"} focus_follows_mouse ${if focus.followMouse then "yes" else "no"} @@ -209,6 +204,8 @@ let ''; in { + meta.maintainers = with maintainers; [ sumnerevans ]; + options = { xsession.windowManager.i3 = { enable = mkEnableOption "i3 window manager."; diff --git a/modules/services/window-managers/i3-sway/lib/functions.nix b/modules/services/window-managers/i3-sway/lib/functions.nix index 9391e6e92..967dbb5e0 100644 --- a/modules/services/window-managers/i3-sway/lib/functions.nix +++ b/modules/services/window-managers/i3-sway/lib/functions.nix @@ -120,6 +120,15 @@ rec { ${optionalString (smartBorders != "off") "smart_borders ${smartBorders}"} ''; + windowBorderString = window: floating: + let + titlebarString = { titlebar, border, ... }: + "${if titlebar then "normal" else "pixel"} ${toString border}"; + in concatStringsSep "\n" [ + "default_border ${titlebarString window}" + "default_floating_border ${titlebarString floating}" + ]; + floatingCriteriaStr = criteria: "for_window ${criteriaStr criteria} floating enable"; windowCommandsStr = { command, criteria, ... }: diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index e38f96af6..da646988e 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -245,7 +245,7 @@ let inherit (commonFunctions) keybindingsStr keycodebindingsStr modeStr assignStr barStr gapsStr - floatingCriteriaStr windowCommandsStr colorSetStr; + floatingCriteriaStr windowCommandsStr colorSetStr windowBorderString; startupEntryStr = { command, always, ... }: '' ${if always then "exec_always" else "exec"} ${command} @@ -265,12 +265,7 @@ let with cfg.config; '' font pango:${concatStringsSep ", " fonts} floating_modifier ${floating.modifier} - default_border ${if window.titlebar then "normal" else "pixel"} ${ - toString window.border - } - default_floating_border ${ - if floating.titlebar then "normal" else "pixel" - } ${toString floating.border} + ${windowBorderString window floating} hide_edge_borders ${window.hideEdgeBorders} focus_wrapping ${if focus.forceWrapping then "yes" else "no"} focus_follows_mouse ${focus.followMouse} diff --git a/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf b/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf index 729605be4..3727068b1 100644 --- a/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf @@ -1,7 +1,7 @@ font pango:monospace 8 floating_modifier Mod1 -new_window normal 2 -new_float normal 2 +default_border normal 2 +default_floating_border normal 2 hide_edge_borders none force_focus_wrapping no focus_follows_mouse no diff --git a/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf b/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf index 1e385e8c7..38ed84422 100644 --- a/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf +++ b/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf @@ -1,7 +1,7 @@ font pango:monospace 8 floating_modifier Mod1 -new_window normal 2 -new_float normal 2 +default_border normal 2 +default_floating_border normal 2 hide_edge_borders none force_focus_wrapping no focus_follows_mouse yes