Some additional sway hotkeys
· 2 min read · August 17, 2026 · #linux #nixos #sway I am still generally enjoying using Wayland with the sway window manager on NixOS. It turns out I really like tiling window managers, it seems to behave reasonably well, and it has a degree of customisability that I’m finding very helpful. The combination of UI customisation via my sway config and automation via kanshi is really rather good.
A couple of recent additions took me a while to find so I thought I’d document here in the usual way.
First is the way I toggle all networking on/off: bind a plausible looking function key (in my case on the laptop keyboard having the glyph for flight mode, and the equivalent function key on my external USB keyboard) to the following shell script which parses the output of nmcli and toggles off/on networking as appropriate:
wayland.windowManager.sway.keybindings =
let
...
net_toggle = pkgs.writeShellScriptBin "net_toggle.sh" ''
if [[ $(nmcli n) =~ enabled ]]; then
nmcli n off
else
nmcli n on
fi
'';
f8 = "exec ${net_toggle}/bin/net_toggle.sh";
...
in
lib.mkOptionDefault {
## bare function keys
...
"F8" = f8;
...
## thinkpad keyboard
...
"XF86WLAN" = f8;
...
};Second was one that’s a bit more subtle but seems to be working ok. One of the things I don’t really have yet is a good mental model for how to navigate the tree (?) of containers in Sway. In particular, sometimes you have a set of windows that seem to occupy an implicit container while sometimes you have some windows sitting inside an explicit container labelled something like V [ w1 w2 ... ] or H [ w1 w2 ... ]. Once I move focus to one of the latter windows via <modifier>+<arrow>1 I can’t then move focus back out with the keyboard, forcing me instead to wiggle the mouse. This is irritating.
So I realised that what I needed was to move focus to the parent container (the one labelled V [ ... ] or H [ ... ]) and then I can move focus left/right/up/down as desired. Which means the following bindings are useful additions as they effectively do just that: move focus to parent, navigate, then move focus back to the child of the navigated-to target:
wayland.windowManager.sway.keybindings =
let
...
in
lib.mkOptionDefault {
...
"${modifier}+Ctrl+Down" = "focus parent, focus down, focus child";
"${modifier}+Ctrl+Left" = "focus parent, focus left, focus child";
"${modifier}+Ctrl+Right" = "focus parent, focus right, focus child";
"${modifier}+Ctrl+Up" = "focus parent, focus up, focus child";
...
};Possibly I should sit down and think about Sway containers and navigation thereof more completely at some point (essentially to answer: is it really just a tree? or are there wrinkles?) to come up with some bindings that make more sense. But the one above has been a significant improvement as it stands. In my case, modifier is set to Mod4 or super which is to say, the Windows key. Purely on the basis that it’s in a convenient place. ↩