Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· OpenAIAi2 WildChat-4.8M (AI2)

how to bind printscreen to sway

  1. User

    how to bind printscreen to sway

  2. Assistant

    In Sway, a Wayland compositor, you will need to configure hotkeys by editing the Sway configuration file which is typically found at ~/.config/sway/config. You can use a program like grim to capture screenshots in Sway.

    First, ensure that grim is installed on your system:

    sudo pacman -S grim # for Arch Linux and derivatives
    sudo apt install grim # for Debian, Ubuntu, and derivatives
    

    Next, open the Sway configuration file (~/.config/sway/config) with your preferred text editor, and bind the print screen key to the screen capture command.

    For example:

    # screenshot binding
    bindsym Print exec grim ~/Pictures/Screenshot-$(date +'%Y-%m-%d-%H%M%S').png
    

    In this line:

    • bindsym is the command used to bind keys in Sway.
    • Print corresponds to the print screen key. You might also see it represented as PrtSc or PrtScn on some keyboards.
    • exec is used to execute the command that follows it.
    • grim is the screenshot utility.
    • ~/Pictures/Screenshot-$(date +'%Y-%m-%d-%H%M%S').png specifies the directory and filename for the screenshot. The $(date +'%Y-%m-%d-%H%M%S') part adds a timestamp to the filename to make it unique.

    After adding the line, save the file and either restart Sway for the changes to take effect or reload the configuration with Mod+Shift+C (where "Mod" is your mod key, often the Windows key).

    Now, pressing the print screen key should take a fullscreen snapshot and save it to your ~/Pictures directory.

    If you want to have more complex screenshot bindings, like capturing a window or selecting an area, you can create more bindings with appropriate grim options or use slurp for selection:

    # window screenshot, requires slurp and focusing on the desired window
    bindsym $mod+Shift+Print exec grim -g "$(swaymsg -t get_tree | jq -r '.. | select(.focused? == true).rect | "\(.x),\(.y) \(.width)x\(.height)"')" ~/Pictures/Screenshot-$(date +'%Y-%m-%d-%H%M%S').png
    
    # selection screenshot, uses slurp to select the area
    bindsym $mod+Print exec grim -g "$(slurp)" ~/Pictures/Screenshot-$(date +'%Y-%m-%d-%H%M%S').png
    

    Make sure to replace $mod with your mod key if necessary, and ensure you have jq and slurp installed if you are using those utilities.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.