You are not logged in.

#1 2016-08-30 12:25:51

Lesmana
Member
Registered: 2015-05-04
Posts: 18

[solved] scrot, maim, and import produces screenshots from the past

I use gnome. When I create screenshots using scrot or maim or import (from imagemagick) then I will "always" get a screenshot from the past. With "always" I mean every invocation after the first in a given gnome session. The first invocation will produce a current screenshot.

Creating a screenshot using gnome-screenshot (either by pressing the print screen key or by invoking from command line) will always create a current screenshot.

More details:
After starting a new gnome session (either by rebooting or by Atl+F2 and r) the first invocation of every tool (scrot, maim or import) will produce a current screenshot. Every further invocation will produce one of the screenshots from the first invocation. Gnome-screenshot always produces a current screenshot.

Let's call the first screenshot from scrot scrot0, the first from maim maim0, and the first from import import0. Further invocations of scrot will produce either scrot0, maim0 or import0. Chosen at random as far as I can tell. The same goes for further invocations of maim or import.

Background information:
Some weeks ago I was messing around with a script which works with screenshots. Screenshots using all tools were working fine back then (as far as I know. was mainly using scrot). Then I stopped working on the script. Fast forward a couple of weeks. I kept my system updated during the weeks. Now I wanted to continue working on the script and noticed the strange behaviour with the screenshots from the past.

There seems to be one other person with a similar problem on the internet: http://askubuntu.com/questions/815005/g … m-the-past
Sadly the discussion went on about his partition problems and stagnated there. Note that I do not have those partition problems whatsoever.

Please help me solve the problem. Or help me to debug this.

Here is some information of my system. Please tell me what other information do you need.

$ uname -a
Linux lestop 4.7.2-1-ARCH #1 SMP PREEMPT Sat Aug 20 23:02:56 CEST 2016 x86_64 GNU/Linux

$ gnome-shell --version
GNOME Shell 3.20.4

$ gnome-screenshot --version
gnome-screenshot 3.20.1

$ scrot --version
scrot version 0.8

$ maim --version
maim v3.4.47
Copyright (C) 2014 Dalton Nell, Maim Contributors
(https://github.com/naelstrof/maim/graphs/contributors)

$ import --version
Version: ImageMagick 6.9.5-5 Q16 x86_64 2016-08-07 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenCL OpenMP 
Delegates (built-in): bzlib cairo fontconfig freetype gslib jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib

Last edited by Lesmana (2017-10-03 09:33:00)

Offline

#2 2016-08-30 13:56:04

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: [solved] scrot, maim, and import produces screenshots from the past

please try running maim from your home folder without parameters twice .

output should look something like this :

$ maim
No file specified, using /home/your-user/1472565040.png
$ maim
No file specified, using /home/your-user/1472565046.png
$ 

Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#3 2016-08-30 17:32:22

Lesmana
Member
Registered: 2015-05-04
Posts: 18

Re: [solved] scrot, maim, and import produces screenshots from the past

I did as you told. Here is the output:

$ maim
No file specified, using /home/lesmana/1472577484.png
$ maim
No file specified, using /home/lesmana/1472577486.png

If run from a fresh gnome session the first invocation will produce a current screenshot. The second invocation will sometimes produce the same as the first screenshot and sometimes produce a current screenshot. Further invocations will repeat older screenshots reliably at least after the third invocation. If run from a "used" gnome session then the screenshots are repeated reliably starting from the first invocation.

I did more tests and but I need some time to compile the results in coherent text. That may take some time.

Offline

#4 2016-10-18 11:03:24

Lesmana
Member
Registered: 2015-05-04
Posts: 18

Re: [solved] scrot, maim, and import produces screenshots from the past

Reporting back after two months. The situation is still the same. I have created some scripts to help me diagnose the problem.

First a script to help me create screenshots:

#! /bin/bash

trap 'echo error exit ; kill 0' EXIT

tools=""
default_tools="gnome import maim scrot"
delay=0
repeat=1
workdir=screenshots

for arg ; do
  case $arg in
    g|gnome) tools="${tools/gnome/} gnome" ;;
    i|import) tools="${tools/import/} import" ;;
    m|maim) tools="${tools/maim/} maim" ;;
    s|scrot) tools="${tools/scrot/} scrot" ;;
    -d*) delay=${arg#-d} ;;
    -r*) repeat=${arg#-r} ;;
    *) workdir=$arg ;;
  esac
done

tools=${tools:-$default_tools}

echo "tools $tools" | tr -s ' '
echo "delay $delay"
echo "repeat $repeat"
echo "workdir $workdir"

seq $delay -1 1 | while read countdown ; do
  echo "delay $countdown"
  sleep 1
done

mkdir $workdir || exit 1
cd $workdir || exit 1

echo "screenshots go"

seq -w $repeat | while read count ; do
  echo "repeat $count"
  sleep 0.5
  for tool in $tools ; do
    case $tool in
      gnome) gnome-screenshot -f gnome-$count.png ; sleep 0.5 ;;
      import) import -window root import-$count.png ;;
      maim) maim maim-$count.png ;;
      scrot) scrot scrot-$count.png ;;
    esac
  done
done

echo "screenshots done"

for filename in *.png ; do
  echo "png2pat $filename"
  png2pat $filename > ${filename/png/pat}
done

echo "tools $tools" | tr -s ' '
echo "workdir $workdir"

trap - EXIT
echo "normal exit"

Example invocation:

$ ./screenshots.sh -d3 -r10 gnome scrot delme4

This will delay 3 seconds (to give time to switch windows). Then it will repeat 10 times:  create screenshots using the tools gnome-screenshot and scrot (in that order). Then it will create pat files from the png files using png2pat (part of xautomation). All files will saved in the directory delme4.

Example output of above invocation:

tools gnome scrot
delay 3
repeat 10
workdir delme4
delay 3
delay 2
delay 1
screenshots go
repeat 01
repeat 02
repeat 03
repeat 04
repeat 05
repeat 06
repeat 07
repeat 08
repeat 09
repeat 10
screenshots done
png2pat gnome-01.png
png2pat gnome-02.png
png2pat gnome-03.png
png2pat gnome-04.png
png2pat gnome-05.png
png2pat gnome-06.png
png2pat gnome-07.png
png2pat gnome-08.png
png2pat gnome-09.png
png2pat gnome-10.png
png2pat scrot-01.png
png2pat scrot-02.png
png2pat scrot-03.png
png2pat scrot-04.png
png2pat scrot-05.png
png2pat scrot-06.png
png2pat scrot-07.png
png2pat scrot-08.png
png2pat scrot-09.png
png2pat scrot-10.png
tools gnome scrot
workdir delme4
normal exit

Yes I like verbose output.

Now a script (actually two scripts) to help me analyze the screenshots:

#! /bin/bash

trap 'echo error exit ; kill 0' EXIT

workdir=screenshots
pattern=pat
show1=

for arg ; do
  case $arg in
    png) pattern=png ;;
    pat) pattern=pat ;;
    1) show1=yes ;;
    *) workdir=$arg ;;
  esac
done


echo "workdir $workdir"
echo "pattern $pattern"
echo "show1 ${show1:-no}"

test -d $workdir || {
  echo "no directory $workdir"
  exit 1
}

find $workdir | grep $pattern | 
  sort | xargs md5sum | awk -v show1=$show1 -f dups.awk

trap - EXIT
echo "normal exit"
#! /bin/awk -f

# expected input is output of md5sum sorted by filename
# output is duplicate count and duplicate filenames

# expects parameter show1 set to true or false

{
  md5sum = $1
  filename = $2
  # map filename to md5sum
  md5sums[filename] = md5sum
  # note first filename for each md5sum
  if(!firstfilenames[md5sum]) {
    firstfilenames[md5sum] = filename
  }
  # note every filename for each md5sum
  dups[md5sum][filename] = 1
}


END {
  # sort array by values, discard old index, overwrite old array
  asort(firstfilenames)
  for(i in firstfilenames) {
    md5sum = md5sums[firstfilenames[i]]
    # sort array by index, discard old values, store in new array
    asorti(dups[md5sum], dupfilenames)
    lengthdupfilenames = length(dupfilenames)
    if(lengthdupfilenames != 1) {
      clustercount += 1
      filesinclustercount += lengthdupfilenames
    } else {
      uniquefilescount += 1
    }
    if(lengthdupfilenames != 1 || show1) {
      print lengthdupfilenames
      for(j in dupfilenames) {
        print dupfilenames[j]
      }
    }
  }
  print "total files:", NR
  print "unique files:", uniquefilescount ? uniquefilescount : 0
  print "clusters:", clustercount
  print "files in clusters:", filesinclustercount
}

Why awk? Because It began as a one-liner using awk to filter out duplicates while maintaining order.

The humble beginnings of my awk script as a one-liner:

find dirname | grep pat | sort | xargs md5sum | awk '!x[$1]++'

With time my requirements grew and so did the scripts.

Example invocation and output of analyze script:

$ ./analyze.sh gnomefirst9
workdir gnomefirst9
pattern pat
show1 no
16
gnomefirst9/gnome-01.pat
gnomefirst9/import-01.pat
gnomefirst9/import-03.pat
gnomefirst9/import-05.pat
gnomefirst9/import-07.pat
gnomefirst9/import-08.pat
gnomefirst9/maim-01.pat
gnomefirst9/maim-03.pat
gnomefirst9/maim-05.pat
gnomefirst9/maim-07.pat
gnomefirst9/maim-08.pat
gnomefirst9/scrot-01.pat
gnomefirst9/scrot-03.pat
gnomefirst9/scrot-05.pat
gnomefirst9/scrot-07.pat
gnomefirst9/scrot-08.pat
16
gnomefirst9/gnome-02.pat
gnomefirst9/import-02.pat
gnomefirst9/import-11.pat
gnomefirst9/import-12.pat
gnomefirst9/import-19.pat
gnomefirst9/import-20.pat
gnomefirst9/maim-02.pat
gnomefirst9/maim-11.pat
gnomefirst9/maim-12.pat
gnomefirst9/maim-19.pat
gnomefirst9/maim-20.pat
gnomefirst9/scrot-02.pat
gnomefirst9/scrot-11.pat
gnomefirst9/scrot-12.pat
gnomefirst9/scrot-19.pat
gnomefirst9/scrot-20.pat
31
gnomefirst9/gnome-04.pat
gnomefirst9/import-04.pat
gnomefirst9/import-06.pat
gnomefirst9/import-09.pat
gnomefirst9/import-10.pat
gnomefirst9/import-13.pat
gnomefirst9/import-14.pat
gnomefirst9/import-15.pat
gnomefirst9/import-16.pat
gnomefirst9/import-17.pat
gnomefirst9/import-18.pat
gnomefirst9/maim-04.pat
gnomefirst9/maim-06.pat
gnomefirst9/maim-09.pat
gnomefirst9/maim-10.pat
gnomefirst9/maim-13.pat
gnomefirst9/maim-14.pat
gnomefirst9/maim-15.pat
gnomefirst9/maim-16.pat
gnomefirst9/maim-17.pat
gnomefirst9/maim-18.pat
gnomefirst9/scrot-04.pat
gnomefirst9/scrot-06.pat
gnomefirst9/scrot-09.pat
gnomefirst9/scrot-10.pat
gnomefirst9/scrot-13.pat
gnomefirst9/scrot-14.pat
gnomefirst9/scrot-15.pat
gnomefirst9/scrot-16.pat
gnomefirst9/scrot-17.pat
gnomefirst9/scrot-18.pat
total files: 80
unique files: 17
clusters: 3
files in clusters: 63
normal exit

This output shows that there are only three different images produced by the many invocations of scrot, maim and import. In this case the images are the repetition of gnome-screenshot 01, 02 and 04.

This is a typical result. Usually there are three clusters. I have never seen more than three clusters. Repeat count above 20 almost always create three cluster. Repeat count 10 or lower may create two or even just one cluster. The clusters usually form around the first few repeats.

Here is an example of an atypical result:

$ ./analyze.sh gnomefirstx52
workdir gnomefirstx52
pattern pat
show1 no
13
gnomefirstx52/gnome-1.pat
gnomefirstx52/import-1.pat
gnomefirstx52/import-2.pat
gnomefirstx52/import-3.pat
gnomefirstx52/import-4.pat
gnomefirstx52/maim-1.pat
gnomefirstx52/maim-2.pat
gnomefirstx52/maim-3.pat
gnomefirstx52/maim-4.pat
gnomefirstx52/scrot-1.pat
gnomefirstx52/scrot-2.pat
gnomefirstx52/scrot-3.pat
gnomefirstx52/scrot-4.pat
4
gnomefirstx52/gnome-5.pat
gnomefirstx52/import-5.pat
gnomefirstx52/maim-5.pat
gnomefirstx52/scrot-5.pat
total files: 20
unique files: 3
clusters: 2
files in clusters: 17
normal exit

Repeat count was 5. There are only two clusters and the second cluster formed with the last repeat.

Last edited by Lesmana (2016-11-04 18:03:15)

Offline

#5 2016-10-18 11:06:41

Lesmana
Member
Registered: 2015-05-04
Posts: 18

Re: [solved] scrot, maim, and import produces screenshots from the past

The last system update changed the situation drastically. I did a system update yesterday. I do a system update about every week. After every system update I tested my screenshot tools using the scripts above to see whether something changed. Now things have changed.

The situation before: gnome-screenshot works fine everytime. Scrot, maim and import works fine on first invocation of gnome session. Every further invocation produces a screenshot of some previous invocation.

The situation now: gnome-screenshot works fine as before. Scrot and maim produces a black image everytime. Import produces an error mesage everytime.

This is the error message of import:

$ import -window root foo
import: unable to read X window image `root': Resource temporarily unavailable @ error/xwindow.c/XImportImage/4983.
import: missing an image filename `foo' @ error/import.c/ImportImageCommand/1287.

This error message seems to be very common on the internet:

import: unable to read X window image `<some id that is not root>': ...

Unfortunately I had no luck getting clues about my problem with the (now black) screenshots.

The output of this seemingly related command also does not help me much:

$ xwininfo -name root
xwininfo: error: No window with name "root" exists!

I am confused. First I get screenshots from the past which no one else seems to be getting. Now I get black screenshots and have no root window. Please help.

Offline

#6 2016-10-18 12:55:25

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: [solved] scrot, maim, and import produces screenshots from the past

The situation now: gnome-screenshot works fine as before. Scrot and maim produces a black image everytime. Import produces an error mesage everytime.

That has a simple explanation :gnome now runs on wayland by default, scrot and main are  designed to run in X .
If you use a display manager, you should have an option to select a "Gnome on X" sesssion .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#7 2016-10-18 13:23:11

Lesmana
Member
Registered: 2015-05-04
Posts: 18

Re: [solved] scrot, maim, and import produces screenshots from the past

Thank you. Gnome using wayland seems to be reason for this behaviour change.

I have posted a follow up: https://bbs.archlinux.org/viewtopic.php?pid=1662309

Offline

#8 2016-11-10 17:37:24

Lesmana
Member
Registered: 2015-05-04
Posts: 18

Re: [solved] scrot, maim, and import produces screenshots from the past

I have verified that the screenshot tools designed to run under X do not work under wayland. This is by design of wayland. For more details read the linked thread.

I want to use those screenshot tools for my automation scripts. My workaround for now is to revert to use X. I assume that X will still be around for a while and that I will miss no feature of wayland for a while.

So that problem outlined above is still bugging me. And it seems that I am alone in the internet with that problem sad

Offline

#9 2016-11-11 13:04:39

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,868

Re: [solved] scrot, maim, and import produces screenshots from the past

And it seems that I am alone in the internet with that problem

Gnome & users appear to prefer gui-apps for everything, scrot maim & import target command-line users.

I think it's time to find out if this problem is specific to gnome.

Could you try testing behaviour with KDE ?
If KDE also has this behaviour, continue testing  with a non-compositing window manager like openbox.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#10 2017-10-03 09:32:21

Lesmana
Member
Registered: 2015-05-04
Posts: 18

Re: [solved] scrot, maim, and import produces screenshots from the past

reporting back one year later.

at least maim works again. scrot and import still produces screenshots from the past.

maim has been rewritten to not use imlib2.
https://github.com/naelstrof/maim/releases/tag/v4.4.58
https://github.com/naelstrof/maim/issues/71

scrot seems to be have been abandoned. all the more reason to use maim.

i have still not tested under kde. sorry.

Offline

Board footer

Powered by FluxBB