How can I easily make screenshots of screen regions on Arch Linux with i3 WM?

About a month ago I switched from Ubuntu 14.04 LTS to Arch and I’m quite happy with this decision. However, I miss some features with my new distro, especially Shift+printscr which in Unity allows selection of a screen region to be captured.

I use i3 WM. So, my question is: how can I configure Unity-like screenshot behaviour to be able to snap screen regions or windows with a keyboard shortcut or something (without digging into window id and console stuff)?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can use import, part of ImageMagick.

Capture a region

This will change your cursor into a crosshair and when you click and drag to form a box, that box will be saved as ss.png.

import ss.png

Capture whole display
import -window root ss.png

You can also replace the word root with the window id to capture a specific window.

Method 2

It’s been a long time since I’d asked this question and it looks like it’s helpful for some of the users. So I provide my own script for making screenshots with xclip and imagemagick packages.

First of all, install the above mentioned dependencies. Then you can do whatever you want with the script below. It supports making a screenshot of a whole screen or a screen region and also it automatically copies a screenshot to a clipboard so you can paste it everywhere (e.i browser or Telegram messenger).

A couple of not so hard to come up with hacks would add a support for capturing specific windows and toggle copying part.

#!/usr/bin/env bash

# screenshots stuff
# TODO: docs

function help_and_exit {
    if [ -n "${1}" ]; then
        echo "${1}"
    fi
    cat <<-EOF
    Usage: scregcp [-h|-s] [<screenshots_base_folder>]

    Take screenshot of a whole screen or a specified region,
    save it to a specified folder (current folder is default)
    and copy it to a clipboard. 

       -h   - print help and exit
       -s   - take a screenshot of a screen region
EOF
    if [ -n "${1}" ]; then
        exit 1
    fi
    exit 0
}

if [ "${1}" == '-h'  ]; then
    help_and_exit
elif [ "${1:0:1}" == '-' ]; then
    if [ "${1}" != '-s' ]; then
        help_and_exit "error: unknown option ${1}"  
    fi
    base_folder="${2}"
else
    base_folder="${1}"
    params="-window root"
fi  

file_path=${base_folder}$( date '+%Y-%m-%d_%H-%M-%S' )_screenshot.png
import ${params} ${file_path}
xclip -selection clipboard -target image/png -i < ${file_path}

And here is my reference shortcuts for an i3wm to make use of this script:

# take a screenshot of a screen region and copy it to a clipboard
bindsym --release Shift+Print exec "scregcp -s /home/ddnomad/pictures/screenshots/"

# take a screenshot of a whole window and copy it to a clipboard
bindsym --release Print exec "scregcp /home/ddnomad/pictures/screenshots/"

Method 3

Flameshot is a decent alternative.

bindsym Print       exec flameshot full
bindsym Shift+Print exec flameshot gui

You can use option -p /path/to/directory to skip selecting the save directory.

Method 4

have you tried scrot a, simple commandline screen capture utility

ref., : https://faq.i3wm.org/question/202/what-do-you-guys-use-for-printscreen/

Method 5

First, install xclip, imagemagick and jq!

pacman -S imagemagick jq xclip

I have this line in my i3 config:
bindsym $mod+Print exec 
    import -window $( 
        i3-msg -t get_tree | 
        jq 'recurse(.nodes[]) | select(.focused).window' 
    ) png:- | 
    xclip -selection clipboard -t image/png

This will put a screenshot of the active window on your clipboard when you press mod (Window / Alt) + Printscreen.

i3-msg -t get-tree gets all windows from i3 as json, then we use jq to get the window id of the focussed window. We pass it to imagemagicks import command and pipe the result to xclip who will put it on the clipboard!

Method 6

Use maim. It’s more actively developed and depends on slop which is way better.

Don’t use scrot. 
Its selection box corrupts and leaves an impression in the screenshot (also the box deforms when resizing) when used over an updating window (say htop).

Method 7

I like shutter for its post-processing capabilities (hand-drawn red circles!) and comprehensive configuration options.

You can grab a screen region by running

shutter --select

You can set up key bindings in .config/i3/config like so:
bindsym Print         exec shutter --full
bindsym Shift+Print   exec shutter --select

It takes a second to load, so you may want to autostart it in the background:
exec shutter --min_at_startup

Shutter will be accessible via a tray icon then, which gives you many useful options beyond the above.

Method 8

Slightly edited the solution by @ddnomad above, here’s the bash version of the script with more explicity and another flag that allows saving only to clipboard.

#! /bin/bash -

help_and_exit() {
  cat <<-EOF
  Usage: scregcp [-h|-s|-c] [<screenshots_base_folder>]

  Take screenshot of a whole screen or a specified region,
  save it to a specified folder (current folder is default)
  and copy it to a clipboard.

    -h   - print help and exit
    -s   - take a screenshot of a screen region
    -c   - save only to clipboard
EOF
    exit 0
}

base_folder="./"
savefile=true
region=false
params="-window root"
while test $# -gt 0; do
  case "$1" in
    -h|--help*)
      help_and_exit
      ;;
    -r|--region*)
      params=""
      shift
      ;;
    -c|--clipboard-only*)
      savefile=false
      shift
      ;;
    *)
      if [[ $1 =~ ^- ]] ; then
        echo "error: unknown flag '$1'"
        help_and_exit
      fi
      base_folder="${1}"
      shift
      ;;
  esac
done

file_path=${base_folder}$( date '+%Y-%m-%d_%H-%M-%S' )_screenshot.png
import ${params} ${file_path}
xclip -selection clipboard -target image/png -i < ${file_path}

if [ "$savefile" = false ] ; then
  rm ${file_path}
fi

Then this is what you add to i3 config:

bindsym --release Shift+Print exec --no-startup-id "/dir/to/script.sh -r $HOME/Pictures/screenshots/"                                   
bindsym --release Control+Shift+Print exec --no-startup-id "/dir/to/script.sh -r -c $HOME/Pictures/screenshots/"                        
bindsym --release Print exec --no-startup-id "/dir/to/script.sh $HOME/Pictures/screenshots/"                                            
bindsym --release Control+Print exec --no-startup-id "/dir/to/script.sh -c $HOME/Pictures/screenshots/"                                 

So the keybinding is:

  • PrtSc = make a screenshot
  • +Control = only save to clipboard
  • +Shift = only capture a specific region of the screen

Method 9

A very simple option if you have it installed or don’t mind installing it is using xfce4-screenshooter and i3 config would be:

bindsym Print exec --no-startup-id xfce4-screenshooter

Caveat: although fairly lightweight there are some dependencies if you are not using any other xfce4 programs

Method 10

This perl6 script takes root, area, window, or delay ScreenShots using import and saves them in a $file and in the clipboard.

#!/usr/bin/env perl6
use v6;

sub print_window(Str $file) {
  qx{xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"} ~~ /(0xS*)/;
  run <import -window>, $0, $file;
}

sub MAIN( Str $option where $option ∈ <root area window delay> ) {
  my $today = DateTime.now( 
    formatter => { 
      sprintf "%04d_%02d_%02d_%02d-%02d-%02d", .year, .month, .day, .hour, .minute, .second 
    } 
  );
  my $file  = "$*HOME/Dades/Imatges/ScreenShots/$today.png";

  given $option {
    when 'root'   { run <import -window root>, $file }
    when 'area'   { run 'import', $file              }
    when 'window' { print_window($file)              }
    when 'delay'  { sleep 10; print_window($file)    }
  }
  run <xclip -selection clipboard -target image/png -i>, $file;
  run <xmessage -nearmouse -timeout 3>, "Screenshot in clipboard, and saved in $today.png";
}

These are the key bindings in i3 to run the script:
bindsym $mod+Print exec Print_Screen root 
bindsym --release $mod+Shift+Print exec Print_Screen area
bindsym $mod+Mod1+Print exec Print_Screen delay
bindsym $mod+Control+Print exec Print_Screen window

Method 11

FeatureShortcut
Full ScreenPrtScrn
SelectionShift + PrtScrn
Active WindowSuper + PrtScrn
Clipboard Full ScreenCtrl + PrtScrn
Clipboard SelectionCtrl + Shift + PrtScrn
Clipboard Active WindowCtrl + Super + PrtScrn

Requirements

  • maim
  • xclip

Set-up

Set this on your i3 config file ~/.i3/config.

## Screenshots
bindsym Print exec --no-startup-id maim "/home/$USER/Pictures/$(date)"
bindsym $mod+Print exec --no-startup-id maim --window $(xdotool getactivewindow) "/home/$USER/Pictures/$(date)"
bindsym Shift+Print exec --no-startup-id maim --select "/home/$USER/Pictures/$(date)"

## Clipboard Screenshots
bindsym Ctrl+Print exec --no-startup-id maim | xclip -selection clipboard -t image/png
bindsym Ctrl+$mod+Print exec --no-startup-id maim --window $(xdotool getactivewindow) | xclip -selection clipboard -t image/png
bindsym Ctrl+Shift+Print exec --no-startup-id maim --select | xclip -selection clipboard -t image/png

source: https://dev.to/dianjuar/i3wm-screenshot-shortcuts-3n7b


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments