### Build and Install SWHKD from Source Source: https://context7.com/waycrate/swhkd/llms.txt Instructions for cloning the repository, setting up the Rust toolchain, building the binary, and installing it system-wide. ```bash git clone https://github.com/waycrate/swhkd cd swhkd make setup make clean make sudo make install make NO_RFKILL_SW_SUPPORT=1 ``` -------------------------------- ### SWHKD Configuration Example Source: https://context7.com/waycrate/swhkd/llms.txt A comprehensive example of an SWHKD configuration file (`swhkdrc`) demonstrating various features including ignoring bindings, launching applications, window management for bspwm, media controls, screenshots, and custom modes for music playback and window resizing. ```bash # ~/.config/swhkd/swhkdrc # Complete SWHKD Configuration Example # Ignore conflicting bindings ignore alt + f4 # ========== APPLICATION LAUNCHERS ========== # Terminal super + return alacritty super + shift + return kitty --class floating # Application launcher super + d rofi -show drun -show-icons # File manager super + e thunar # Web browser super + w firefox # ========== WINDOW MANAGEMENT (bspwm) ========== # Focus/swap windows in direction super + {_,shift + }{h,j,k,l} bspc node -{f,s} {west,south,north,east} # Focus/send to desktop super + {_,shift + }{1-9,0} bspc {desktop -f,node -d} '^{1-9,10}' # Close/kill window super + {_,shift + }q bspc node -{c,k} # Toggle floating/fullscreen super + {s,f} bspc node -t {floating,fullscreen} # ========== MEDIA CONTROLS ========== xf86audioraisevolume wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ xf86audiolowervolume wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- xf86audiomute wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle xf86monbrightnessup brightnessctl set +10% xf86monbrightnessdown brightnessctl set 10%- # ========== SCREENSHOT ========== print scrot ~/Pictures/Screenshots/%Y-%m-%d_%H-%M-%S.png shift + print scrot -s ~/Pictures/Screenshots/%Y-%m-%d_%H-%M-%S.png # ========== MUSIC MODE ========== super + m @enter music && notify-send "Music Mode" "Press q to exit" mode music swallow q @escape && notify-send "Normal Mode" {n,p,space} mpc {next,prev,toggle} {minus,equal} mpc volume {-5,+5} endmode # ========== RESIZE MODE ========== super + r @enter resize && notify-send "Resize Mode" "hjkl to resize, q to exit" mode resize swallow oneoff {h,j,k,l} bspc node -z {left -20 0,bottom 0 20,top 0 -20,right 20 0} q @escape endmode ``` -------------------------------- ### Setup SWHKD Systemd User Service Source: https://context7.com/waycrate/swhkd/llms.txt This snippet outlines the steps to create and manage the SWHKD service using systemd for user sessions. It includes creating the necessary directory, defining the service file, and enabling/starting the service. ```bash mkdir -p ~/.config/systemd/user cat > ~/.config/systemd/user/swhkd.service << 'EOF' [Unit] Description=Simple Wayland HotKey Daemon BindsTo=graphical-session.target After=graphical-session.target [Service] Type=simple ExecStart=/bin/bash -c 'swhks & exec sudo swhkd' Restart=on-failure RestartSec=1 [Install] WantedBy=graphical-session.target EOF systemctl --user daemon-reload systemctl --user enable swhkd.service systemctl --user start swhkd.service systemctl --user status swhkd.service ``` -------------------------------- ### Run SWHKD Daemon and Server Source: https://context7.com/waycrate/swhkd/llms.txt Methods to start the swhks server and swhkd daemon, including elevated privilege requirements. ```bash # Method 1: Run with sudo swhks & sudo swhkd # Method 2: Setuid approach sudo chown root:root /usr/local/bin/swhkd sudo chmod u+s /usr/local/bin/swhkd swhks & swhkd ``` -------------------------------- ### Configure SWHKD Hotkeys Source: https://context7.com/waycrate/swhkd/llms.txt Examples of defining key bindings, modifiers, and command execution in the swhkdrc configuration file. ```bash super + return alacritty super + shift + return kitty super + d rofi -show drun print scrot ~/Pictures/screenshot_%Y-%m-%d_%H-%M-%S.png ``` -------------------------------- ### Define Basic Keybindings with Prefixes Source: https://context7.com/waycrate/swhkd/llms.txt Demonstrates the use of @ for command execution on key release and ~ for passing hotkeys through to applications. ```swhkd @super + shift + f pcmanfm ~super + v notify-send "Paste detected" ~@super + c notify-send "Copy released" ``` -------------------------------- ### Include External Configuration Files Source: https://context7.com/waycrate/swhkd/llms.txt Organize configurations by importing external files using absolute paths. ```swhkd include /home/username/.config/swhkd/apps.conf include /home/username/.config/swhkd/wm.conf include /home/username/.config/swhkd/media.conf ``` -------------------------------- ### Configure Media and System Keys Source: https://context7.com/waycrate/swhkd/llms.txt Maps multimedia keys for volume, brightness, and playback control using pactl, wpctl, and playerctl. ```swhkd xf86audioraisevolume pactl set-sink-volume @DEFAULT_SINK@ +5% xf86monbrightnessup brightnessctl set +10% xf86audioplay playerctl play-pause ``` -------------------------------- ### SWHKD and SWHKS Command Line Options Source: https://context7.com/waycrate/swhkd/llms.txt Common flags for customizing daemon behavior, specifying devices, and debugging. ```bash swhkd --help swhkd --config /path/to/custom/swhkdrc swhkd --cooldown 100 swhkd --device /dev/input/event0 swhks --debug ``` -------------------------------- ### Execute Multi-line Commands Source: https://context7.com/waycrate/swhkd/llms.txt Shows how to span complex logic across multiple lines using backslashes. ```swhkd super + ctrl + alt + {Left,Down,Up,Right} n=10; \ { d1=left; d2=right; dx=-$n; dy=0; \ , d1=bottom; d2=top; dx=0; dy=$n; \ , d1=top; d2=bottom; dx=0; dy=-$n; \ , d1=right; d2=left; dx=$n; dy=0; \ } \ bspc node --resize $d1 $dx $dy || bspc node --resize $d2 $dx $dy ``` -------------------------------- ### Implement Mode-based Keybindings Source: https://context7.com/waycrate/swhkd/llms.txt Defines switchable modes to create context-specific shortcuts, including mode options like swallow and oneoff. ```swhkd mode music q @escape && echo "normal" > ~/.config/waybar/swhkd-mode n mpc next endmode mode resize swallow oneoff h bspc node -z left -20 0 escape @escape endmode ``` -------------------------------- ### Use Brace Expansion for Hotkeys Source: https://context7.com/waycrate/swhkd/llms.txt Utilizes brace expansion to define multiple related hotkeys efficiently, supporting lists and ranges. ```swhkd super + {_,shift + }{h,j,k,l} bspc node -{f,s} {west,south,north,east} super + {1-9} bspc desktop -f '^{1-9}' super + shift + {1-9} bspc node -d '^{1-9}' super + {\,, .} bspc node -f {next.local,prev.local} super + {minus, equal} pactl set-sink-volume @DEFAULT_SINK@ {-5%,+5%} ``` -------------------------------- ### Control SWHKD via Unix Signals Source: https://context7.com/waycrate/swhkd/llms.txt Manage the daemon at runtime using signals to pause, resume, or reload configurations without restarting. ```bash sudo pkill -USR1 swhkd sudo pkill -USR2 swhkd sudo pkill -HUP swhkd ``` -------------------------------- ### Apply Ignore Directives Source: https://context7.com/waycrate/swhkd/llms.txt Prevents specific key combinations from being captured by the daemon. ```swhkd ignore alt + print ignore super + alt + backspace ignore ctrl + alt + delete ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.