sway: transfer config to a nix expression

So cool! It means I can finally have a common config with local customizations
per-machine.
This commit is contained in:
Jez Cope 2020-11-26 08:49:52 +00:00
parent 1c7780b4cb
commit 33bef3e703
6 changed files with 291 additions and 374 deletions

View File

@ -4,15 +4,6 @@
home.packages = with pkgs;
let gn = pkgs.gnome3;
in [
wofi
dmenu
swayidle
grim
slurp
light
wl-clipboard
j4-dmenu-desktop
bemenu
keybase-gui
gn.gnome-tweaks
@ -30,8 +21,6 @@
vlc
v4l-utils
darktable
pamixer
playerctl
pavucontrol
vorbis-tools
audacity
@ -52,7 +41,6 @@
".face".source = ../dotfiles/images/cat.jpg;
};
xdg.configFile = {
# "sway".source = ../dotfiles/sway;
"wofi".source = ../dotfiles/wofi;
"waybar".source = ../dotfiles/waybar;
"kitty" = {

254
home/jez/bits/sway.nix Normal file
View File

@ -0,0 +1,254 @@
{ config, pkgs, lib, ... }:
let
modifier = "Mod4";
left = "h";
down = "t";
up = "n";
right = "s";
bg-image =
"~/Pictures/Wallpapers/Unsplash/ales-krivec-n4rF9mEEzNg-unsplash.jpg";
lock-timeout = 300;
doff-timeout = 600;
opacity = "0.95";
colors = {
primary = "#007D78";
primary-light = "#10C9C2";
secondary = "#7D2F05";
secondary-light = "#CA5010";
fg = "#E9EDF0";
bg = "#000000";
};
grim-date-fmt = "+%Y-%m-%d-%H%M%S";
cmds = rec {
kitty = pkgs.kitty + /bin/kitty;
bemenu = builtins.concatStringsSep " " [
(pkgs.bemenu + /bin/bemenu)
''--fn "Iosevka 15"''
"--ignorecase --bottom --grab"
''--hf "${colors.primary-light}"''
''--hb "${colors.primary}"''
''--nf "${colors.fg}"''
''--nb "${colors.bg}EE"''
''--tf "${colors.secondary}"''
''--tb "${colors.bg}EE"''
''--ff "${colors.secondary-light}"''
''--fb "${colors.bg}EE"''
''--prompt "run:"''
"--list 12"
"--monitor -1"
];
swayidle = pkgs.swayidle + /bin/swayidle;
playerctl = pkgs.playerctl + /bin/playerctl;
pamixer = pkgs.pamixer + /bin/pamixer;
term = "${kitty} --single-instance";
initial-term = "${kitty} --session ~/.config/kitty/sessions/default.conf";
menu = ''
${pkgs.j4-dmenu-desktop}/bin/j4-dmenu-desktop \
--dmenu='${bemenu}' --term='${kitty}' --no-exec | xargs swaymsg exec --'';
idle = ''
${swayidle} -w \
timeout ${lock-timeout} 'swaylock -f -i ${bg-image}' \
timeout ${doff-timeout} 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'swaylock -f -i ${bg-image}'
'';
};
in {
wayland.windowManager.sway = {
enable = true;
wrapperFeatures.gtk = true;
config = {
inherit modifier left down up right;
bars = [ ];
gaps.inner = 16;
fonts = [ "Iosevka 12" ];
window.titlebar = true;
window.border = 0;
colors = rec {
focused = rec {
border = "${colors.primary}bb";
text = "${colors.fg}";
indicator = "${colors.secondary-light}aa";
background = border;
childBorder = border;
};
unfocused = rec {
border = "${colors.bg}88";
text = "${colors.fg}";
indicator = text;
background = border;
childBorder = text;
};
focusedInactive = unfocused;
};
floating = {
inherit modifier;
border = 2;
criteria = let
classes = [ "zoom" "Keepassx2" "Sonata" ];
ids = [
"pavucontrol"
"blueman-manager"
"ario"
"zenity"
"yubico.com.yubioath-desktop"
];
in (map (class: { inherit class; }) classes)
++ (map (app_id: { inherit app_id; }) ids);
};
window.commands = [
{
criteria = { title = "."; };
command = "title_format '%title'";
}
{
criteria = { title = "Picture-in-Picture"; };
command =
"floating enable, sticky enable, move window position 0 px 0 px";
}
{
criteria = { title = ".* - Sharing Indicator"; };
command = "floating enable, move window position 0px 0px";
}
{
criteria = { class = "t-engine64"; };
command = "fullscreen enable";
}
{
criteria = { class = "Emacs"; };
command = "opacity ${opacity}";
}
{
criteria = { app_id = "kitty"; };
command = "opacity ${opacity}";
}
];
output."*".bg = "${bg-image} fill";
input."type:keyboard" = {
xkb_layout = "us";
xkb_options = "compose:ralt";
};
startup = [
{ command = "${pkgs.foldingathome}/bin/FAHClient --send-pause"; }
{ command = "${pkgs.xorg.xrdb}/bin/xrdb -load ~/.Xresources"; }
{ command = "${pkgs.mako}/bin/mako"; }
{ command = cmds.initial-term; }
{
command =
"systemctl --user import-environment SWAYSOCK && systemctl --user start waybar";
always = true;
}
# { command = "zfs load-key trough/vms/win10"; }
];
keybindings = let mod = config.wayland.windowManager.sway.config.modifier;
in {
"${mod}+Return" = "exec ${cmds.term}";
"${mod}+d" = "exec ${cmds.menu}";
"${mod}+Shift+c" = "kill";
"${mod}+${left}" = "focus left";
"${mod}+${down}" = "focus down";
"${mod}+${up}" = "focus up";
"${mod}+${right}" = "focus right";
"${mod}+Left" = "focus left";
"${mod}+Down" = "focus down";
"${mod}+Up" = "focus up";
"${mod}+Right" = "focus right";
"${mod}+Shift+${left}" = "move left";
"${mod}+Shift+${down}" = "move down";
"${mod}+Shift+${up}" = "move up";
"${mod}+Shift+${right}" = "move right";
"${mod}+Shift+Left" = "move left";
"${mod}+Shift+Down" = "move down";
"${mod}+Shift+Up" = "move up";
"${mod}+Shift+Right" = "move right";
"${mod}+Ctrl+${left}" = "move workspace to output left";
"${mod}+Ctrl+${right}" = "move workspace to output right";
"${mod}+Ctrl+Left" = "move workspace to output left";
"${mod}+Ctrl+Right" = "move workspace to output right";
"${mod}+Shift+b" = "splith";
"${mod}+Shift+v" = "splitv";
"${mod}+a" = "focus parent";
"${mod}+j" = "layout stacking";
"${mod}+w" = "layout tabbed";
"${mod}+e" = "layout toggle split";
"${mod}+f" = "fullscreen toggle";
"${mod}+Comma" = "border toggle";
"${mod}+Shift+p" = "sticky toggle";
"${mod}+Shift+space" = "floating toggle";
"${mod}+space" = "focus mode_toggle";
"${mod}+1" = "workspace number 1";
"${mod}+2" = "workspace number 2";
"${mod}+3" = "workspace number 3";
"${mod}+4" = "workspace number 4";
"${mod}+5" = "workspace number 5";
"${mod}+6" = "workspace number 6";
"${mod}+7" = "workspace number 7";
"${mod}+8" = "workspace number 8";
"${mod}+9" = "workspace number 9";
"${mod}+0" = "workspace number 10";
"${mod}+Shift+1" = "move container to workspace number 1";
"${mod}+Shift+2" = "move container to workspace number 2";
"${mod}+Shift+3" = "move container to workspace number 3";
"${mod}+Shift+4" = "move container to workspace number 4";
"${mod}+Shift+5" = "move container to workspace number 5";
"${mod}+Shift+6" = "move container to workspace number 6";
"${mod}+Shift+7" = "move container to workspace number 7";
"${mod}+Shift+8" = "move container to workspace number 8";
"${mod}+Shift+9" = "move container to workspace number 9";
"${mod}+Shift+0" = "move container to workspace number 10";
"${mod}+Shift+minus" = "move scratchpad";
"${mod}+minus" = "scratchpad show";
"${mod}+g" = ''
exec ${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" "Downloads/screenshot-$(date ${grim-date-fmt}).png"'';
"${mod}+l" = "exec pkill -USR1 swayidle";
"${mod}+Shift+e" =
"exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'";
"${mod}+r" = "mode resize";
XF86AudioPlay = "exec ${cmds.playerctl} play-pause";
XF86AudioNext = "exec ${cmds.playerctl} next";
XF86AudioPrev = "exec ${cmds.playerctl} prev";
XF86AudioStop = "exec ${cmds.playerctl} stop";
XF86AudioRaiseVolume = "exec ${cmds.pamixer} --increase 5";
XF86AudioLowerVolume = "exec ${cmds.pamixer} --decrease 5";
};
};
extraConfig = ''
titlebar_padding 7 7
titlebar_border_thickness 3
title_align right
'';
};
home.packages = with pkgs; [ wofi light wl-clipboard ];
}

View File

@ -1,361 +0,0 @@
# Default config for sway
#
# Copy this to ~/.config/sway/config and edit it to your liking.
#
# Read `man 5 sway` for a complete reference.
### Variables
#
# Logo key. Use Mod1 for Alt.
set $mod Mod4
# Home row direction keys, like vim
set $lt h
set $dn t
set $up n
set $rt s
# Your preferred terminal emulator
set $term kitty --single-instance
set $initial_term kitty --session ~/.config/kitty/sessions/default.conf
set $tmux_attach kitty --session ~/.config/kitty/sessions/tmux.conf
# Your preferred application launcher
# Note: pass the final command to swaymsg so that the resulting window can be opened
# on the original workspace that the command was run on.
# set $menu dmenu_path | bemenu | xargs swaymsg exec --
# set $menu wofi -D drun-print_command=true --show drun | sed 's/%[uU]//g' | xargs swaymsg exec --
# set $menu wofi --show drun
set $menu j4-dmenu-desktop --dmenu='bemenu --fn "Iosevka 15" --ignorecase --bottom --grab --hb "#007D78" --nb "#000000EE" --tb "#000000EE" --tf "#7D2F05" --ff "#CA5010" --fb "#000000EE" --hf "#10C9C2" --prompt "run:" --list 12 --monitor -1' --term='kitty' --no-exec | xargs swaymsg exec --
set $volinc 5
set $media_ppse playerctl play-pause
set $media_next playerctl next
set $media_prev playerctl prev
set $media_stop playerctl stop
set $media_volu pamixer --increase 5
set $media_vold pamixer --decrease 5
set $lock_timeout 300
set $doff_timeout 600
set $bg_image ~/Pictures/Wallpapers/Unsplash/ales-krivec-n4rF9mEEzNg-unsplash.jpg
set $lock_image $bg_image
set $bg_normal $bg_image fill
set $bg_boring #444444 solid_color
output * bg $bg_normal
gaps inner 16
# gaps outer 8
### Output configuration
#
set $output_main 'Samsung Electric Company C27JG5x H4ZMA00132'
set $output_alt 'Unknown HP E233 CNC7500L7Q'
output $output_main {
resolution 2560x1440@144Hz
position 0 0
}
output $output_alt {
resolution 1920x1080@60Hz
transform 270
}
workspace 10 output $output_alt $output_main
### Idle configuration
exec swayidle -w \
timeout $lock_timeout 'swaylock -f -i $lock_image' \
timeout $doff_timeout 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
before-sleep 'swaylock -f -i $lock_image'
# This will lock your screen after 300 seconds of inactivity, then turn off
# your displays after another 300 seconds, and turn your screens back on when
# resumed. It will also lock your screen before your computer goes to sleep.
### Pause foldingathome on login
# The idle config above will restart it on idle
exec FAHClient --send-pause
### PolKit authentication agent
exec /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1
### Unlock encrypted Windows 10 VM volume
exec zfs load-key trough/vms/win10
### Load Xresources
exec xrdb -load ~/.Xresources
### Open a terminal
exec $initial_term
### Appearance (fonts & colours)
font "pango:Iosevka, 12"
titlebar_padding 7 7
titlebar_border_thickness 3
set $def_border normal 0
default_border $def_border
client.focused #007D78bb #007D78bb #E9EDF0 #CA5010aa #007D78bb
# client.focused #000000bb #000000bb #ffffff
client.focused_inactive #00000088 #00000088 #ffffff
client.unfocused #00000088 #00000088 #ffffff
title_align right
for_window [title="."] title_format '%title'
# for_window [title="."] title_format '%title <i>(%app_id:%class)</i>'
### Input configuration
#
# Example configuration:
#
# input "2:14:SynPS/2_Synaptics_TouchPad" {
# dwt enabled
# tap enabled
# natural_scroll enabled
# middle_emulation enabled
# }
#
# You can get the names of your inputs by running: swaymsg -t get_inputs
# Read `man 5 sway-input` for more information about this section.
input "type:keyboard" {
xkb_layout us
xkb_options compose:ralt
}
input "1:1:AT_Translated_Set_2_keyboard" {
xkb_layout dvorak
xkb_options compose:ralt,ctrl:nocaps
}
exec mako
### Key bindings
#
# Basics:
#
# Start a terminal
bindsym $mod+Return exec $term
bindsym $mod+Shift+Return exec $tmux_attach
# Kill focused window
bindsym $mod+Shift+c kill
# Start your launcher
bindsym $mod+d exec $menu
# Drag floating windows by holding down $mod and left mouse button.
# Resize them with right mouse button + $mod.
# Despite the name, also works for non-floating windows.
# Change normal to inverse to use left mouse button for resizing and right
# mouse button for dragging.
floating_modifier $mod normal
# Reload the configuration file
bindsym $mod+Shift+r reload
# Exit sway (logs you out of your Wayland session)
bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'
#
# Moving around:
#
# Move your focus around
bindsym $mod+$lt focus left
bindsym $mod+$dn focus down
bindsym $mod+$up focus up
bindsym $mod+$rt focus right
# Or use $mod+[up|down|left|right]
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right
# Move the focused window with the same, but add Shift
bindsym $mod+Shift+$lt move left
bindsym $mod+Shift+$dn move down
bindsym $mod+Shift+$up move up
bindsym $mod+Shift+$rt move right
# Ditto, with arrow keys
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right
#
# Workspaces:
#
# Switch to workspace
bindsym $mod+1 workspace 1
bindsym $mod+2 workspace 2
bindsym $mod+3 workspace 3
bindsym $mod+4 workspace 4
bindsym $mod+5 workspace 5
bindsym $mod+6 workspace 6
bindsym $mod+7 workspace 7
bindsym $mod+8 workspace 8
bindsym $mod+9 workspace 9
bindsym $mod+0 workspace 10
# Move focused container to workspace
bindsym $mod+Shift+1 move container to workspace 1
bindsym $mod+Shift+2 move container to workspace 2
bindsym $mod+Shift+3 move container to workspace 3
bindsym $mod+Shift+4 move container to workspace 4
bindsym $mod+Shift+5 move container to workspace 5
bindsym $mod+Shift+6 move container to workspace 6
bindsym $mod+Shift+7 move container to workspace 7
bindsym $mod+Shift+8 move container to workspace 8
bindsym $mod+Shift+9 move container to workspace 9
bindsym $mod+Shift+0 move container to workspace 10
# Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default.
# Outputs:
# Toggle second monitor
bindsym $mod+Ctrl+a output $output_alt toggle
# Move current workspace
bindsym $mod+Ctrl+$lt move workspace to output left
bindsym $mod+Ctrl+$rt move workspace to output right
bindsym $mod+Ctrl+Left move workspace to output left
bindsym $mod+Ctrl+Right move workspace to output right
#
# Layout stuff:
#
# You can "split" the current object of your focus with
# $mod+b or $mod+v, for horizontal and vertical splits
# respectively.
bindsym $mod+b splith
bindsym $mod+v splitv
# Switch the current container between different layout styles
bindsym $mod+j layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split
# Make the current focus fullscreen
bindsym $mod+f fullscreen
# Switch between borderless and not
bindsym $mod+Comma border toggle
# Toggle the current focus between tiling and floating mode
bindsym $mod+Shift+space floating toggle
# Swap focus between the tiling area and the floating area
bindsym $mod+space focus mode_toggle
# Move focus to the parent container
bindsym $mod+a focus parent
#
# Scratchpad:
#
# Sway has a "scratchpad", which is a bag of holding for windows.
# You can send windows there and get them back later.
# Move the currently focused window to the scratchpad
bindsym $mod+Shift+minus move scratchpad
# Show the next scratchpad window or hide the focused scratchpad window.
# If there are multiple scratchpad windows, this command cycles through them.
bindsym $mod+minus scratchpad show
#bindsym $mod+l exec swaylock -c $lock_colour
bindsym $mod+l exec pkill -USR1 swayidle
#
# Useful key bindings
#
# Toggle sticky status for current (floating) window
bindsym $mod+p sticky toggle
# Take screen grab
set $date_fmt "+%Y-%m-%d-%H%M%S"
bindsym $mod+g exec grim -g "$(slurp)" "Downloads/screenshot-$(date $date_fmt).png"
bindsym $mod+apostrophe output * background $bg_boring
bindsym $mod+quotedbl output * background $bg_normal
#
# Resizing containers:
#
mode "resize" {
# left will shrink the containers width
# right will grow the containers width
# up will shrink the containers height
# down will grow the containers height
bindsym $lt resize shrink width 10px
bindsym $dn resize grow height 10px
bindsym $up resize shrink height 10px
bindsym $rt resize grow width 10px
# Ditto, with arrow keys
bindsym Left resize shrink width 10px
bindsym Down resize grow height 10px
bindsym Up resize shrink height 10px
bindsym Right resize grow width 10px
# Return to default mode
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+r mode "resize"
# Multimedia control
bindsym XF86AudioPlay exec $media_ppse
bindsym XF86AudioNext exec $media_next
bindsym XF86AudioPrev exec $media_prev
bindsym XF86AudioStop exec $media_stop
bindsym XF86AudioRaiseVolume exec $media_volu
bindsym XF86AudioLowerVolume exec $media_vold
#
# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
# bar {
# position top
# swaybar_command waybar
# When the status_command prints a new line to stdout, swaybar updates.
# The default just shows the current date and time.
# status_command while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done
# colors {
# statusline #ffffff
# background #323232
# inactive_workspace #323232 #323232 #5c5c5c
# }
# }
exec_always systemctl --user import-environment SWAYSOCK && systemctl --user start waybar
set $opacity 0.95
for_window [class="zoom"] floating enable
for_window [title=".*Zoom meeting"] \
floating disable
for_window [class="Keepassx2"] floating enable
for_window [class="Sonata"] floating enable
for_window [app_id="pavucontrol"] floating enable
for_window [app_id="blueman-manager"] \
floating enable
for_window [app_id="ario"] floating enable
for_window [app_id="zenity"] floating enable
for_window [app_id="yubico.com.yubioath-desktop"] \
floating enable
for_window [title="Picture-in-Picture"] \
floating enable, sticky enable, move window position 0 px 0 px
for_window [title=".* - Sharing Indicator"] \
floating enable, move window position 0px 0px
for_window [class="t-engine64"] fullscreen enable
for_window [class="Emacs"] opacity $opacity
for_window [app_id="Alacritty"] opacity $opacity
include /etc/sway/config.d/*

View File

@ -11,6 +11,7 @@ in {
imports = [
./bits/desktop.nix
./bits/sway.nix
./bits/shell.nix
./bits/firefox.nix
./bits/emacs.nix

View File

@ -1,5 +1,12 @@
{ pkgs, ... }:
{ config, pkgs, lib, ... }:
{
home.packages = with pkgs; [ steam ];
wayland.windowManagers.sway.config.input = {
"1:1:AT_Translated_Set_2_keyboard" = {
xkb_layout = "dvorak";
xkb_options = "compose:ralt,ctrl:nocaps";
};
};
}

View File

@ -25,4 +25,32 @@ in {
enable = true;
mpd.host = "127.0.0.1";
};
wayland.windowManager.sway = let
outputs = {
main = "Samsung Electric Company C27JG5x H4ZMA00132";
alt = "Unknown HP E233 CNC7500L7Q";
};
mod = config.wayland.windowManager.sway.config.modifier;
in {
config = {
keybindings = {
"${mod}+Ctrl+a" = "output ${outputs.alt} toggle";
};
output = {
"${outputs.main}" = {
resolution = "2560x1440@144Hz";
position = "0 0";
};
"${outputs.alt}" = {
resolution = "1920x1080@60Hz";
transform = "270";
};
};
};
extraConfig = ''
workspace 10 output ${outputs.alt} ${outputs.main}
'';
};
}