From d633afe0d96d47e6fc40327386608c9c068197d0 Mon Sep 17 00:00:00 2001
From: arcnmx <arcnmx@users.noreply.github.com>
Date: Sun, 15 Jan 2023 10:20:13 -0800
Subject: [PATCH] i3-sway: config.focus.wrapping deprecates forceWrapping
 (#3467)

Stop using the legacy syntax described in the i3 documentation:
https://i3wm.org/docs/userguide.html#_focus_wrapping
---
 .../services/window-managers/i3-sway/i3.nix   | 21 +++++++++----------
 .../window-managers/i3-sway/lib/options.nix   | 19 +++++++++++++++--
 .../services/window-managers/i3-sway/sway.nix |  7 +++++--
 .../i3/i3-bar-focused-colors-expected.conf    |  2 +-
 .../i3/i3-followmouse-expected.conf           |  2 +-
 .../window-managers/i3/i3-fonts-expected.conf |  2 +-
 .../i3/i3-keybindings-expected.conf           |  2 +-
 .../i3/i3-workspace-default-expected.conf     |  2 +-
 .../i3/i3-workspace-output-expected.conf      |  2 +-
 9 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/modules/services/window-managers/i3-sway/i3.nix b/modules/services/window-managers/i3-sway/i3.nix
index f28b9b67..b4742c78 100644
--- a/modules/services/window-managers/i3-sway/i3.nix
+++ b/modules/services/window-managers/i3-sway/i3.nix
@@ -160,7 +160,7 @@ let
         "floating_modifier ${floating.modifier}"
         (windowBorderString window floating)
         "hide_edge_borders ${window.hideEdgeBorders}"
-        "force_focus_wrapping ${lib.hm.booleans.yesNo focus.forceWrapping}"
+        "focus_wrapping ${focus.wrapping}"
         "focus_follows_mouse ${lib.hm.booleans.yesNo focus.followMouse}"
         "focus_on_window_activation ${focus.newWindow}"
         "mouse_warping ${if focus.mouseWarping then "output" else "none"}"
@@ -256,16 +256,15 @@ in {
         ++ flatten (map (b:
           optional (isList b.fonts)
           "Specifying i3.config.bars[].fonts as a list is deprecated. Use the attrset version instead.")
-          cfg.config.bars);
+          cfg.config.bars) ++ [
+            (mkIf (any (s: s.workspace != null) cfg.config.startup)
+              ("'xsession.windowManager.i3.config.startup.*.workspace' is deprecated, "
+                + "use 'xsession.windowManager.i3.config.assigns' instead."
+                + "See https://github.com/nix-community/home-manager/issues/265."))
+            (mkIf cfg.config.focus.forceWrapping
+              ("'xsession.windowManager.i3.config.focus.forceWrapping' is deprecated, "
+                + "use 'xsession.windowManager.i3.config.focus.wrapping' instead."))
+          ];
     })
-
-    (mkIf (cfg.config != null
-      && (any (s: s.workspace != null) cfg.config.startup)) {
-        warnings = [
-          ("'xsession.windowManager.i3.config.startup.*.workspace' is deprecated, "
-            + "use 'xsession.windowManager.i3.config.assigns' instead."
-            + "See https://github.com/nix-community/home-manager/issues/265.")
-        ];
-      })
   ]);
 }
diff --git a/modules/services/window-managers/i3-sway/lib/options.nix b/modules/services/window-managers/i3-sway/lib/options.nix
index d04a1176..3fe0b755 100644
--- a/modules/services/window-managers/i3-sway/lib/options.nix
+++ b/modules/services/window-managers/i3-sway/lib/options.nix
@@ -510,13 +510,28 @@ in {
             if (isSway && isBool val) then (lib.hm.booleans.yesNo val) else val;
         };
 
+        wrapping = mkOption {
+          type = types.enum [ "yes" "no" "force" "workspace" ];
+          default = {
+            i3 = if cfg.config.focus.forceWrapping then "force" else "yes";
+            # the sway module's logic was inverted and incorrect,
+            # so preserve it for backwards compatibility purposes
+            sway = if cfg.config.focus.forceWrapping then "yes" else "no";
+          }.${moduleName};
+          description = ''
+            Whether the window focus commands automatically wrap around the edge of containers.
+
+            See <link xlink:href="https://i3wm.org/docs/userguide.html#_focus_wrapping"/>
+          '';
+        };
+
         forceWrapping = mkOption {
           type = types.bool;
           default = false;
           description = ''
-            Whether to force focus wrapping in tabbed or stacked container.
+            Whether to force focus wrapping in tabbed or stacked containers.
 
-            See <link xlink:href="https://i3wm.org/docs/userguide.html#_focus_wrapping"/>
+            This option is deprecated, use <option>focus.wrapping</option> instead.
           '';
         };
 
diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix
index fdcbaabc..a18a4212 100644
--- a/modules/services/window-managers/i3-sway/sway.nix
+++ b/modules/services/window-managers/i3-sway/sway.nix
@@ -271,7 +271,7 @@ let
           "floating_modifier ${floating.modifier}"
           (windowBorderString window floating)
           "hide_edge_borders ${window.hideEdgeBorders}"
-          "focus_wrapping ${lib.hm.booleans.yesNo focus.forceWrapping}"
+          "focus_wrapping ${focus.wrapping}"
           "focus_follows_mouse ${focus.followMouse}"
           "focus_on_window_activation ${focus.newWindow}"
           "mouse_warping ${
@@ -442,7 +442,10 @@ in {
         ++ flatten (map (b:
           optional (isList b.fonts)
           "Specifying sway.config.bars[].fonts as a list is deprecated. Use the attrset version instead.")
-          cfg.config.bars);
+          cfg.config.bars) ++ [
+            (mkIf cfg.config.focus.forceWrapping
+              "sway.config.focus.forceWrapping is deprecated, use focus.wrapping instead.")
+          ];
     })
 
     {
diff --git a/tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf b/tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf
index 92f23a92..3b8fca8a 100644
--- a/tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf
+++ b/tests/modules/services/window-managers/i3/i3-bar-focused-colors-expected.conf
@@ -3,7 +3,7 @@ floating_modifier Mod1
 default_border normal 2
 default_floating_border normal 2
 hide_edge_borders none
-force_focus_wrapping no
+focus_wrapping yes
 focus_follows_mouse yes
 focus_on_window_activation smart
 mouse_warping output
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 27234b96..dccf535a 100644
--- a/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf
+++ b/tests/modules/services/window-managers/i3/i3-followmouse-expected.conf
@@ -3,7 +3,7 @@ floating_modifier Mod1
 default_border normal 2
 default_floating_border normal 2
 hide_edge_borders none
-force_focus_wrapping no
+focus_wrapping yes
 focus_follows_mouse no
 focus_on_window_activation smart
 mouse_warping output
diff --git a/tests/modules/services/window-managers/i3/i3-fonts-expected.conf b/tests/modules/services/window-managers/i3/i3-fonts-expected.conf
index d85d978e..8e8cb9da 100644
--- a/tests/modules/services/window-managers/i3/i3-fonts-expected.conf
+++ b/tests/modules/services/window-managers/i3/i3-fonts-expected.conf
@@ -3,7 +3,7 @@ floating_modifier Mod1
 default_border normal 2
 default_floating_border normal 2
 hide_edge_borders none
-force_focus_wrapping no
+focus_wrapping yes
 focus_follows_mouse yes
 focus_on_window_activation smart
 mouse_warping output
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 b3b4c33d..2b7251d2 100644
--- a/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf
+++ b/tests/modules/services/window-managers/i3/i3-keybindings-expected.conf
@@ -3,7 +3,7 @@ floating_modifier Mod1
 default_border normal 2
 default_floating_border normal 2
 hide_edge_borders none
-force_focus_wrapping no
+focus_wrapping yes
 focus_follows_mouse yes
 focus_on_window_activation smart
 mouse_warping output
diff --git a/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf b/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf
index d7fe4b61..baca1411 100644
--- a/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf
+++ b/tests/modules/services/window-managers/i3/i3-workspace-default-expected.conf
@@ -3,7 +3,7 @@ floating_modifier Mod1
 default_border normal 2
 default_floating_border normal 2
 hide_edge_borders none
-force_focus_wrapping no
+focus_wrapping yes
 focus_follows_mouse yes
 focus_on_window_activation smart
 mouse_warping output
diff --git a/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf b/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf
index dedad29e..a51edb9a 100644
--- a/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf
+++ b/tests/modules/services/window-managers/i3/i3-workspace-output-expected.conf
@@ -3,7 +3,7 @@ floating_modifier Mod1
 default_border normal 2
 default_floating_border normal 2
 hide_edge_borders none
-force_focus_wrapping no
+focus_wrapping yes
 focus_follows_mouse yes
 focus_on_window_activation smart
 mouse_warping output