2023-02-25 18:04:58 -03:00
{ config , pkgs , . . . }:
let
2024-05-30 16:54:58 -03:00
inherit ( pkgs . uservars )
key
accent
font
theme
;
2023-02-25 18:04:58 -03:00
inherit ( theme ) color ;
inherit ( pkgs ) lib ;
mod = " M o d 4 " ;
menu = " w l a u n c h e r " ;
terminal = " a l a c r i t t y " ;
_lock = pkgs . writeShellScriptBin " _ l o c k " ''
2023-11-21 18:01:20 -03:00
$ { pkgs . sway } /bin/swaymsg mode default
2023-02-25 18:04:58 -03:00
$ { pkgs . swaylock } /bin/swaylock - f
systemctl - - user start swayidle . service
'' ;
_suspend = pkgs . writeShellScriptBin " _ s u s p e n d " ''
2024-02-23 12:01:24 -03:00
$ { pkgs . sway } /bin/swaymsg mode default
systemctl - - user start swayidle . service
2023-02-25 18:04:58 -03:00
systemctl suspend
'' ;
# mod+1 to swich to workspace 1
# mod+shift+1 to move to workspace 1
2024-05-30 16:54:58 -03:00
workspace_binds = lib . forEachMerge ( lib . range 1 10 ) (
i :
2023-02-25 18:04:58 -03:00
let
key = toString ( lib . mod i 10 ) ;
workspaceNumber = toString i ;
in
{
" ${ mod } + ${ key } " = " w o r k s p a c e n u m b e r ${ workspaceNumber } " ;
2024-05-30 16:54:58 -03:00
" ${ mod } + S h i f t + ${ key } " = " m o v e c o n t a i n e r t o w o r k s p a c e n u m b e r ${ workspaceNumber } " ;
}
) ;
2023-02-25 18:04:58 -03:00
prev_next_binds =
let
2024-05-30 16:54:58 -03:00
maybe_window = key : if ( lib . strings . hasInfix " b u t t o n " key ) then " - - w h o l e - w i n d o w " else " " ;
makePrevNextBindFunction = (
prev_or_next :
2023-02-25 18:04:58 -03:00
map ( key : {
2024-05-30 16:54:58 -03:00
" ${ maybe_window key } ${ mod } + ${ key } " = " w o r k s p a c e ${ prev_or_next } _ o n _ o u t p u t " ;
} )
) ;
2023-02-25 18:04:58 -03:00
prev_binds = makePrevNextBindFunction " p r e v " [
key . tabL
" b r a c k e t l e f t "
" P r i o r "
" b u t t o n 9 "
" b u t t o n 4 "
" S h i f t + T a b "
] ;
next_binds = makePrevNextBindFunction " n e x t " [
key . tabR
" b r a c k e t r i g h t "
" N e x t "
" b u t t o n 8 "
" b u t t o n 5 "
" T a b "
] ;
in
lib . mergeAttrsSet ( prev_binds ++ next_binds ) ;
# focus, move, resize, (focus and move output)
# for every direction with both arrow keys and vim keys
movement_binds =
let
2024-05-30 16:54:58 -03:00
directions = [
" L e f t "
" U p "
" R i g h t "
" D o w n "
] ;
2023-02-25 18:04:58 -03:00
makeVimKeys = ( k : key . ${ lib . toLower k } ) ;
makeArrowKeys = ( k : k ) ;
2024-05-30 16:54:58 -03:00
makeResizeCommand =
direction :
2023-02-25 18:04:58 -03:00
{
Left = " s h r i n k w i d t h 2 0 p x " ;
Up = " s h r i n k h e i g h t 2 0 p x " ;
Right = " g r o w w i d t h 2 0 p x " ;
Down = " g r o w h e i g h t 2 0 p x " ;
2024-05-30 16:54:58 -03:00
}
. ${ direction } ;
2023-02-25 18:04:58 -03:00
in
2024-05-30 16:54:58 -03:00
lib . forEachMerge
[
makeVimKeys
makeArrowKeys
]
(
prefixFun :
lib . forEachMerge directions (
direction :
let
resize_cmd = makeResizeCommand direction ;
keyBind = prefixFun direction ;
in
{
# Move focus
" ${ mod } + ${ keyBind } " = " f o c u s ${ direction } " ;
# Move window
" ${ mod } + S h i f t + ${ keyBind } " = " m o v e ${ direction } " ;
# Resize window
" ${ mod } + C o n t r o l + ${ keyBind } " = " r e s i z e ${ resize_cmd } " ;
# focus output
" ${ mod } + m o d 1 + ${ keyBind } " = " f o c u s o u t p u t ${ direction } " ;
# Move workspace to output
" ${ mod } + m o d 1 + S h i f t + ${ keyBind } " = " m o v e w o r k s p a c e o u t p u t ${ direction } " ;
}
)
) ;
2023-02-25 18:04:58 -03:00
parenting_binds = {
" ${ mod } + e q u a l " = " f o c u s p a r e n t " ;
" ${ mod } + m i n u s " = " f o c u s c h i l d " ;
" ${ mod } + r " = " l a y o u t t o g g l e s p l i t " ;
" ${ mod } + t " = " l a y o u t t o g g l e s p l i t t a b b e d s t a c k i n g " ;
" ${ mod } + b " = " s p l i t h " ;
" ${ mod } + v " = " s p l i t v " ;
" ${ mod } + a " = " f o c u s p a r e n t " ;
## TODO:
# "${mod}+Shift+minus" = "move scratchpad";
# "${mod}+minus" = "scratchpad show";
} ;
audio_binds = {
XF86AudioRaiseVolume = " e x e c v o l u m e s h - i 1 0 " ;
XF86AudioLowerVolume = " e x e c v o l u m e s h - d 1 0 " ;
XF86AudioMute = " e x e c v o l u m e s h - t " ;
2024-05-30 16:54:58 -03:00
XF86AudioMicMute = " e x e c p a c t l s e t - s o u r c e - m u t e @ D E F A U L T _ S O U R C E @ t o g g l e " ;
2023-02-25 18:04:58 -03:00
# Control media
XF86AudioPlay = " e x e c p l a y e r c t l p l a y - p a u s e " ;
XF86AudioPause = " e x e c p l a y e r c t l p l a y - p a u s e " ;
XF86AudioNext = " e x e c p l a y e r c t l n e x t " ;
XF86AudioPrev = " e x e c p l a y e r c t l p r e v i o u s " ;
} ;
system_binds = {
" - - l o c k e d C t r l + ${ mod } + z " = " e x e c ${ _suspend } / b i n / _ s u s p e n d " ;
2023-05-04 19:32:12 -03:00
" ${ mod } + A l t + c " = " e x e c ${ pkgs . _sway_idle_toggle } / b i n / _ s w a y _ i d l e _ t o g g l e " ;
2023-02-25 18:04:58 -03:00
} ;
screenshot_binds = {
# Screens to file
" P r i n t " = " e x e c ${ pkgs . screenshotsh } / b i n / s c r e e n s h o t s h d e f " ;
# Screen area to file
" S h i f t + P r i n t " = " e x e c ${ pkgs . screenshotsh } / b i n / s c r e e n s h o t s h a r e a " ;
# Screen area to clipboard
2024-05-30 16:54:58 -03:00
" C o n t r o l + S h i f t + P r i n t " = " e x e c ${ pkgs . screenshotsh } / b i n / s c r e e n s h o t s h a r e a - c l i p " ;
2023-02-25 18:04:58 -03:00
# Focused monitor to clipboard
" C o n t r o l + P r i n t " = " e x e c ${ pkgs . screenshotsh } / b i n / s c r e e n s h o t s h c l i p " ;
} ;
other_binds = {
" ${ mod } + p " = " e x e c ${ pkgs . wpass } / b i n / w p a s s " ;
" ${ mod } + s " = " e x e c ${ menu } " ;
" ${ mod } + g " = " e x e c ${ pkgs . demoji } / b i n / d e m o j i - - l a n g p t - - f a l l b a c k - - c o p y - - ${ pkgs . wdmenu } / b i n / w d m e n u " ;
" ${ mod } + c " = " e x e c ${ pkgs . color_picker } / b i n / c o l o r _ p i c k e r " ;
" ${ mod } + R e t u r n " = " e x e c ${ terminal } " ;
" ${ mod } + C t r l + R e t u r n " = " e x e c t h u n a r " ;
" ${ mod } + S h i f t + s " = " e x e c g r i m - | s w a p p y - f - " ;
" ${ mod } + C t r l + v " = " e x e c w l - p a s t e | t e s s e r a c t - l p o r - - | w l - c o p y " ;
" ${ mod } + k " = " e x e c s h o w k e y s " ;
2023-05-31 20:42:55 -03:00
" ${ mod } + A l t + x " = " e x e c p k i l l w l - c r o s s h a i r | | e x e c w l - c r o s s h a i r " ;
2023-02-25 18:04:58 -03:00
" ${ mod } + x " = " k i l l " ;
" ${ mod } + m " = " m o d e a u d i o " ;
2024-05-30 16:54:58 -03:00
" ${ mod } + e s c a p e " = " m o d e p a s s t h r o u g h ; e x e c n o t i f y - s e n d ' P a s s t h r o u g h o n ' " ;
2024-02-02 13:43:33 -03:00
" ${ mod } + c t r l + k " = " e x e c s w a y m s g i n p u t t y p e : p o i n t e r e v e n t s d i s a b l e d " ;
" ${ mod } + c t r l + s h i f t + k " = " e x e c s w a y m s g i n p u t t y p e : p o i n t e r e v e n t s e n a b l e d " ;
2023-02-25 18:04:58 -03:00
" ${ mod } + f " = " f u l l s c r e e n t o g g l e " ;
" ${ mod } + S h i f t + s p a c e " = " f l o a t i n g t o g g l e " ;
" ${ mod } + s p a c e " = " f o c u s m o d e _ t o g g l e " ;
" ${ mod } + c t r l + s p a c e " = " s t i c k y t o g g l e " ;
" ${ mod } + S h i f t + c " = " r e l o a d " ;
# "${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'";
2023-09-27 11:07:00 -03:00
# https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/1731
" ${ mod } + C t r l + S h i f t + A l t + l " = " e x e c x d g - o p e n h t t p s : / / w w w . l i n k e d i n . c o m " ;
2023-02-25 18:04:58 -03:00
} ;
in
{
wayland . windowManager . sway . config . keybindings = lib . mergeAttrsSet [
other_binds
workspace_binds
prev_next_binds
movement_binds
audio_binds
system_binds
parenting_binds
screenshot_binds
] ;
}