Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: Rich on March 19, 2013, 03:27:45 AM

Title: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 03:27:45 AM
This is a modified version of screenshot.sh that will produce a png of the window you click on. It depends on xwininfo
to run so you need to install xorg-7.(5 or 6)-bin.tcz only.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 03:33:05 AM
I forgot to mention, if you click on the desktop, it will create a screenshot.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 19, 2013, 04:22:14 AM
Excellent! :D

One observation: the aterm from which command is executed must not overlap the window clicked on, or it would end up being included in the windowshot.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 06:57:11 AM
Hi tinypoodle
That is correct. The "picture" will be of whatever is visible on the screen inside the coordinates of that particular
window.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 19, 2013, 07:00:59 AM
Not being Rich but just assuming you were replying to my post...

Also, I found that areas of windows outside screen borders will be painted gray.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: beroje on March 19, 2013, 07:09:29 AM
very good
Two windows, one superimposed on the other.
Clicking on the rear window also captures the front.

Muy bueno
Dos ventanas, una superpuesta a la otra.
Al hacer clic en la ventana posterior tambien se captura la frontal.

(http://i49.tinypic.com/2lo3hwo.png)
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 07:12:37 AM
Hi tinypoodle
Quote
Not being Rich but just assuming you were replying to my post...
Lack of sleep, copied/pasted the wrong name, corrected.

That's because  imlib2_grab  can only save what is painted on the screen, but since it uses the windows coordinates
and dimensions, it fills in what it can't read in gray. In fact, I once read through some of the documentaion for
imlib2_grab  and I seem to recall it was mention there too.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 07:13:44 AM
Hi beroje
Glad you like it.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 19, 2013, 07:16:32 AM
That makes all sense and still an advantage over having a full screenshot when only a window is required.
I'd assume the gray areas should be well compressible by png.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 07:29:28 AM
Hi tinypoodle
Quote
I'd assume the gray areas should be well compressible by png.
Not as much as you might think. I took the same shot as the one attached to my first post but with the window
halfway off the screen and the file size went from ~16K to ~15K. On my system the off screen section was black.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 19, 2013, 07:33:51 AM
The semantic difference between "assume" and "test"... :P

And probably black is preferable over gray as look.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 19, 2013, 07:37:27 AM
Hmm, I got 68Kb with an estimated quarter of window visible versus 171Kb with same full window, so I guess it may depend.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 12:52:55 PM
Hi tinypoodle
The results I got may be do to the fact that I used the editor with just the posted script in it. I slid the window to the
right obscuring the right half of the window which consisted of a lot of white space and may have already compressed
fairly well when doing a capture.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 19, 2013, 01:08:23 PM
Such factors most likely could explain the differences.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: hiro on March 19, 2013, 03:38:18 PM
Elegant. I'm using it as my default from now on, but I removed the sleep.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 19, 2013, 09:29:53 PM
Hi hiro
Since I don't know why that one second sleep command was put in there, I didn't remove it. I though it might have
been to allow you time to move the mouse pointer somewhere out of the way, but from what I've seen, the mouse
pointer is not captured.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: hiro on March 20, 2013, 04:21:29 AM
I guess in the original version it was meant for you to have some time to arrange things, like bringing the right window to the front or hiding what you invoked screenshot.sh from, but with this addition it shouldn't be needed I think.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 20, 2013, 04:43:45 AM
Once xwininfo is invoked pointer device can't be used to arrange anything, while there is unlimited time to use keyboard before selecting window.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 20, 2013, 07:27:08 AM
Hi tinypoodle
That may be, but the sleep command is after xwininfo has finished executing, leaving you one second before
imlib2_grab runs.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: tinypoodle on March 20, 2013, 08:10:56 AM
Ah yes, correct!
And it seems that if switching desktop within that 1 sec and the selected window does not exist in desktop chosen at time of execution imlib2_grab, then there is a popup but no screenshot saved...
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on March 20, 2013, 08:48:32 AM
Hi tinypoodle
Switching the desktop probably changes the root window. In order to capture the window you clicked on, imlib2.grab
needs to know its position, size, etc. I believe that involves making a series of calls to X starting with the root windows
ID to find all the child window IDs until a match is found. If the window you clicked on does not exist on that desktop,
it won't be found and nothing is captured. Even if it could be found, you would get a black (or gray) image since the
image imlib2.grab creates is of what is visible on the screen.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: curaga on March 20, 2013, 09:15:18 AM
I've been using a similar script, though mine pipes xwd through a couple netpbm tools.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: beroje on July 06, 2013, 12:06:37 PM
imlib2_grab not in /usr/bin/ , added local/
(http://i40.tinypic.com/2ymsgtt.png)
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on July 06, 2013, 01:54:13 PM
Hi beroje
Yes, that was copied verbatim from the original screenshot.sh. Maybe it would be better to omit the path altogether.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: coreplayer2 on September 01, 2013, 01:09:13 PM
Would make a great extension  for the repo  :P
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: coreplayer2 on September 01, 2013, 01:19:30 PM
...or added to Xprogs  to compliment " screenshot " :thumbup:
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: eltone on January 11, 2014, 09:47:34 PM
re: TCP 5.1, windowshot.sh

hi,

This script cannot find imlib2_grab.

Please patch xorg.

eltone
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Juanito on January 11, 2014, 10:07:05 PM
is the imlib2-bin extension loaded?
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: eltone on January 12, 2014, 12:11:39 AM
is the imlib2-bin extension loaded?

Dear Juanito:
Both imlib2-bin.tcz & xorg-7.7-bin.tcz were loaded.

Everything appears ok until attempting to find the .png in the home directory.  The file never got written to disk!

Sincerely,
eltone
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: Rich on January 12, 2014, 08:41:01 AM
Hi eltone
Did you read replies #22 and 23? Try changing:
Code: [Select]
/bin/sh -c "/usr/bin/imlib2_grab -id $WINDOW_ID $HOME/$filename"to:
Code: [Select]
/bin/sh -c "imlib2_grab -id $WINDOW_ID $HOME/$filename"in the script.
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: eltone on January 13, 2014, 02:56:35 PM
. . .read replies #22 and 23

Dear Rich:

Your script is now fully functional, thanks!


Sincerely,
eltone
Title: Re: Creating a "windowshot" instead of a screenshot
Post by: nitram on November 04, 2015, 03:37:25 PM
This script with minor modifications approved by Rich was just submitted to TC6 x86 as  windowshot.tcz  - coming to a repo near you! Tacky desktop icon courtesy me. Noteworthy: In addition to crisp window screenshots user can also click on desktop space to produce a nice screen grab of the entire desktop, including open windows, wbar icons, conky output, fluxbox panel.