Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Screenshot Woes (Active Window and More)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Chiitoo
Administrator
Administrator


Joined: 28 Feb 2010
Posts: 2571
Location: Here and Away Again

PostPosted: Sun Nov 13, 2011 2:09 am    Post subject: [SOLVED] Screenshot Woes (Active Window and More) Reply with quote

Huh, what? [SOLVED] and 0 views? Well yeah, it just so happened that while typing this, I think I may have found what I was looking for, which is quite funny since I have been looking for a long time. Basically since I started using Linux full-time around a year ago. And I take a lot of screenshots!
I feel like posting about the problem anyways, as it might (I hope) at some point of time help someone else, as I have found many a soul with the same'ish question(s), but the answers didn't quite do it for me.

I will of course include the current solution, probably as the final thought of the post.


Sorry if this seems long. You can mostly skim through it and get the gist of it, though. \ö/

So I am on a quest for glo... utility, that deals with screenshots. More specifically, taking and saving them. Done deal, the deal is done, might say, but it has proved to be quite the challenge to find out even one that would be just right. For the perfect one, think of Fraps, which I actually bought in the past (I know, crazy right!?) and I never really could believe it how difficult it could be to find one for Linux. Of course, there is not so much need for what I want I guess, in general.

Of course, Fraps goes mainly to the gaming and such, and I do indeed take screenshots of other things too, such as terminals, internet browsers, etc., but for that part there is an abundance of utilities already found.

Now, the main problem is that I want it to be silent, fast, invisible, bindable, and able to take the shot of the active/focused window. Not necessarily in that order.

Firstly, as a KDE-user, there is ksnapshot, which is very OK, however, I very rarely need and even less often want to have a chat with the screenshot at the time of taking and saving it. Imagine a heated battle with the beastliest beasts, the grievous-most monster of monsters, the... well, you get the picture, I'm sure, and you take the screenshot and the box with options as to what to do with it pops up. This obviously is not too great. One way to go along with it is to just Alt+Tab back to the game, right, and later on save the files but of course, that is not really a good way to deal with it. I've had a lot of them there, waiting, and would an error kill something they might be all lost. Not to mention I often have several different applications going so an Alt+Tab to the screenshot-app at the wrong time is no fun, too!

As far as I know, ksnapshot, just as pretty much every other similar app, does not have the ability to 'work silently'.

Now a long time ago I found out about scrot.
Now this one comes very close to what I want. It's fast, and I can bind it into whatever key I want to, and, it even works without making a noise! It does lack one important thing, however, and that is to take a screenshot of the currently active window. If it could do that, it should pretty much be it. Ultimately, I could use this for those shots that require the speed, but having to crop the image later on can be a chore, and even though it is not always required, it more than often is.

Most, if not all of them have the option to take a screenshot of the currently active window, but you need to select it with your mouse, which is more than inconvenient.

Enter import, from imagemagick.
This one has more than enough options and ways to use them, and might come even closer to it than scrot. Quoting Taking a Screenshot at ArchWiki:

ArchWiki wrote:
Screenshot of the active/focused window

The following script takes a screenshot of the currently focused window. It works with EWMH/NetWM compatible X Window Managers. To avoid overwriting previous screenshots, the current date is used as the filename.
Code:
#!/bin/bash
 activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
 activeWinId=${activeWinLine:40}
 import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png

Alternatively, the following should work regardless of EWMH support:
Code:
import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png

Using the script above, I get even closer to it, however, there is one major snag: A delay of approximately 1 second from pressing a key to actually taking the screenshot. I tried slicing the script into parts trying stuff like:
Code:
time xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"

and it gets done very fast so it's not that part what takes time. Actually, issuing the import command and clicking the mouse-button as fast as I can, it will take around the same time, a second, to process so it has to be something with the actual import command, or how I am using it.


So, any ideas? ^^;
Also, thanks for reading!


And now, the conclusion (for now anyways).

Mainly thanks to this post at ImageMagick.org as well as the script from ArchWiki. All of that information is of course everywhere, basically, but those are where I stumbled upon them.

Either way, what I thought of before already, but I guess only just now really tried to do, is combine the script for import with xwd and convert. I mainly decided to do it after noticing that it was actually the import command that was taking so long to do its thing.

Bam:
Code:
#!/bin/bash
activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
activeWinId=${activeWinLine:40}
#import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png
xwd -id "$activeWinId" |convert xwd: /tmp/$(date +%F_%H%M%S_%N).png

Not sure what difference is between xwd: and xwd:- as seen in the post there, I guess it will eventually come to me. Either way, this feels like it's working just the way I want. Obviously my scripting and such knowledge is very small, but I'm learning!
The above script I would save to a file, and then just assign 'sh path_and_filename' to the chosen key.


I do hope this helps someone, and, if anyone has any comments about any of this, other tips and tricks, caveats, et cetera, please do share. ^^
Again, thanks for reading!
_________________
Kindest of regardses.
Back to top
View user's profile Send private message
bobobo1618
n00b
n00b


Joined: 31 Oct 2012
Posts: 1
Location: Australia

PostPosted: Wed Oct 31, 2012 12:37 pm    Post subject: Reply with quote

I had this exact problem. THANK YOU!!!
Back to top
View user's profile Send private message
ppurka
Advocate
Advocate


Joined: 26 Dec 2004
Posts: 3256

PostPosted: Wed Oct 31, 2012 1:23 pm    Post subject: Reply with quote

Yes. import is really slow. Use imlib2_grab (comes from imlib2) if you want a fast screenshot application.
_________________
emerge --quiet redefined | E17 vids: I, II | Now using kde5 | e is unstable :-/
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum