28 October 2015

Linux inside Android inside Windows.


If you have seen the movie Inception (2010) you may have an idea of how is this.


Laptop - Dell Inspiron (12 GB RAM [0])
--> Windows 8 running Vmware Workstation 10.
----> A VM running Android 4.4 inside Workstation.
------> A Linux running in a chroot environment inside Android.


[0] Could have done this with 4GB or less

You can connect to that Linux in a variety of ways, from inside and outside the Android VM. To name a few: vnc, ssh, X.

Tools used:
- Vmware workstation
- Linux Deploy [1] to install the chroot Linux inside Android

I also tried Complete Linux Installer [2] but didn't manage to run the Linux. Linux Deploy allowed debug mode and log files so I could know what was failing and could do something about it. With Complete Linux Installer I was blind.

[1] https://play.google.com/store/apps/details?id=ru.meefik.linuxdeploy&hl=en
[2] https://play.google.com/store/apps/details?id=com.zpwebsites.linuxonandroid

- I don't remember where did I get the Android VM from, but the vm came on this file Android_4.4_r2.7z

- I also installed XServer XSDL to visualize individual applications from within the android. Viewing the whole Linux desktop on android through VNC is ok for a moment, but not for much more, besides, I just need one application.

[3] https://play.google.com/store/apps/details?id=x.org.server&hl=en


MOST things didn't work on the first attempt, so patience and perseverance are key ingredients.

Saludos / Kind regards,
Ruben

11 October 2015

Screenshots to clipboard, with image processing and who knows what else....



My personal toolbox for screenshots

Problem: I wanted to be able to take special screenshots (directly to clipboard) with minimal effort and intrussion. Just ONE click, no matter where I am.

Note: This is using Linux Debian LXDE.


Solutions progress:

1. First I created some individual scripts, each one on a file.
The problem was that I just wanted to click somewhere to run it, and in LXDE it is very cumbersome to add shortcuts to programs.
After having 3+ scripts I was annoyed by the work needed every time I had to update the scripts placed on a panel bar.

2. I thought on creating my own GUI and from there launch scripts.
I came across zenity and yal, being the last one more what I needed.

Initially I used buttons, but every time you press them the program ends, so I had to create a loop to rerun the program and reposition the window in a suitable position (minimal intrusion). [see CODE1]


3. Searching for examples of implementations of buttons in yal I came across

http://crunchbang.org/forums/viewtopic.php?id=31899
This one gave me a very neat structure to put scripts behind other type of buttons. Wonderful!!
Ah! No loop needed.


4. One of the scripts I was using was focusing on the active window.
My problem was that I wanted my GUI always on the top (sticky) and thus it was always grabbing the attention of the screenshot.

I played for a while with   xprop and wmctrl to put the GUI behind, take the snapshot and then take it back to the front, but it was not working, since it never stopped being the active window.

I created CODE2 to monitor the progress of who is who.

Finally going back to the parameters of the screenshot program (import of imagemagick) I changed the plan and instead of taking the active window and then apply operations to the result, I decided to take a shot of the whole screen and recalculate the position for the operations. So now the problem of active window and focus is gone.


5. Taking the screenshot with import is fine, as far as you don't require a manually specified region, which works, but not 100% of the time.

Here is a nice summary of other tools and the bugs of import

https://www.win.tue.nl/~aeb/linux/misc/import/screenshot.html


6. Then I wanted to apply some image processing to some of the screenshots.

With imagemagick you can draw arrows, insert text etc, but it was taking me a while to get it right because .... well, you have to code SVG on the command.

So I decided to create a transparent image with the things I wanted to add on top of the screenshot (the screenshot is the base image) and then merge them. That's easier said than done.

This page finally put me on the right track
http://www.imagemagick.org/Usage/compose/

The final and easy answer was
# composite   -geometry +185+40 'foreground.png' background.png   png:- (if writing to stdout)
# composite   -geometry +185+40 'foreground.png' -   png:-     (if reading from stdin)
# composite   -geometry +185+40 'foreground.png' background.png   out.png


7. For the issue of screenshot of a region. I had to resort to other programs, but they would not write to stdout.

I tried to trick them writing to a temporal pipe (see http://stackoverflow.com/questions/7756609/pass-stdout-as-file-name-for-command-line-util-answer-use-named-pipes ) but they would fail. So using a temp file was needed.


On CODE3 I put my whole thing together.

I hope you find this useful.









########################## CODE1 ###############################

function yalwindow {

action=$(yad   --title "-Robot" --width=50  --on-top \
    --button="A:1" \
--text="" \
--buttons-layout="center" \
    --button="B:2" \
    --text=" " \
--button="C:3" \
    --text "Choose action:" \
)
ret=$?


case $ret in
    1) cmd="/home/CCC/bin/snapshot-to-clipboard--search.sh" ;;
    2) cmd="/home/CCC/bin/snapshot-to-clipboard--search.sh" ;;
    3) cmd="/home/CCC/bin/snapshot-to-clipboard--search.sh" ;;
    esac

eval exec $cmd &
}



# end of yalwindow function
#---------------------------------------

while true;
  do
  $(sleep 1; wmctrl -r "-Robot" -b add,above;)&
  yalwindow;
  #wmctrl -r "-Robot" -b add,above;
done;


#################################################################################



############### CODE2 ########################################

function whoiswho {
activeWin="$(xprop -root | sed -n 's/^_NET_ACTIVE_WINDOW(WINDOW): window id # //p' | cut -b 3-88 )";
clipboardWin="$(xprop -root | sed -n 's/^_NET_ACTIVE_WINDOW(WINDOW): window id # //p' | cut -b 3-88 )";
selectionWin="$(xprop -root | sed -n 's/^_NET_ACTIVE_WINDOW(WINDOW): window id # //p' | cut -b 3-88 )";
echo "active"; wmctrl -l | grep -i $activeWin;
echo "clipboard"; wmctrl -l | grep -i $clipboardWin;
echo "selection"; wmctrl -l | grep -i $selectionWin;
}

##########################################################



############### CODE3 ########################################

#!/bin/bash
# Copyleft @ 2015


# ============== define functions and export them =====================
#------------------------------------------------------------------------------------

# snapshot-to-clipboard--region
function sc-region {

# import fails very often
# import -quality 92  -bordercolor black  -border 2x2  png:-  | xclip -selection c -t image/png ;};


# scrot and gnome-screenshot needs an output file
# scrot -s  --quality 92  /tmp/snapshot-with-scrot.png ;
# cat /tmp/snapshot-with-scrot.png  |  convert - -bordercolor black  -border 2x2  png:-  | xclip -selection c -t image/png ;

gnome-screenshot  --area -f /tmp/gnome-screenshot-out.png;
cat /tmp/gnome-screenshot-out.png | convert -  -quality 92  -bordercolor black  -border 2x2  png:-  | xclip -selection c -t image/png;
};
export -f sc-region ;

#------------------------------------------------------------------------------------

# snapshot-to-clipboard--search
function sc-search {
xwd -nobdrs  -root  |  convert - -quality 92 -crop 850x406+34+152  -bordercolor black  -border 2x2  png:-  | xclip -selection c -t image/png;};
export -f sc-search ;
#------------------------------------------------------------------------------------

# snapshot-to-clipboard--mock
function sc-mock {
xwd -nobdrs  -root  |  convert - -quality 92 -crop 850x406+34+152  -bordercolor black  -border 2x2  png:-  | xclip -selection c -t image/png;};
export -f sc-mock ;
#------------------------------------------------------------------------------------


# snapshot-to-clipboard-- one
function sc-one {
xwd -nobdrs  -root  |  convert - -quality 92 -crop 850x588+34+152  -bordercolor black  -border 2x2  png:-  | xclip -selection c -t image/png;};
export -f sc-business ;
#------------------------------------------------------------------------------------

# snapshot-to-clipboard-- just
function sc-just {
xwd -nobdrs  -root  |  convert - -quality 92 -crop 850x588+34+152  -bordercolor black  -border 2x2  png:- | composite   -geometry +185+40 '/home/CC/bin/yf2.png' -   png:-   | xclip -selection c -t image/png;};
export -f sc-just ;


# xwd -nobdrs  -root  |  convert - -quality 92 -crop 850x588+34+152  -bordercolor black  -border 2x2  png:-  | xclip -selection c -t image/png;};

# xwd -nobdrs  -root  |  convert - -quality 92 -crop 850x588+34+152  -bordercolor black  -border 2x2  png:- | composite -  -geometry +185+40 /home/CC/bin/yf2.png   | xclip -selection c -t image/png;};

# composite -geometry +185+40 yf2.png yb.png  YYY.png

#----------------------------------------------------------------



# ====================== creates yad dialog =============================
yad \
--form \
--columns 1 \
--center \
--width 50 \
--height 150 \
--on-top \
--title "-Robot" \
--field "C:BTN" "bash -c "sc-search"" \
--field ":LBL" "" \
--field "R:BTN" "bash -c "sc-region"" \
--field ":LBL" "" \
--field "M:BTN" "bash -c "sc-mock"" \
--field ":LBL" "" \
--field "O:BTN" "bash -c "sc-one"" \
--field ":LBL" "" \
--field "J:BTN" "bash -c "sc-just"" \
--button "gtk-quit:1" &


# Move the window to the right

sleep 1; wmctrl -r "-Robot"  -e  0,1261,293,0,0






##########################################################

Too Cool for Internet Explorer