This simple magnifier, is a modification of Richard Rost's
Widowshot.
http://forum.tinycorelinux.net/index.php/topic,15086.0.html It may help some users of TinyCore who, like myself, have difficulty with the font used in the builtin FLTK tools.
Every year or so I attempt to find out how to change the font in FLTK/Fluid, but at low level, the documentation is at best sketchy, possibly non-existent. This time round I thought 'why not just enlarge the problem windows ?'.
I had in mind a script using dimly remembered
Windowshot followed by
convert from
Imagemagik, and then an image viewer.
However I soon realized that something much simpler would probably do what I had in mind.
Windowshot is basically a shell script that uses
imlib2_grab to save its target while
imlib2_view, also part of TC's the imlib2 extension, can resize the image you give it to display.
So we have :
#!/bin/sh
# Script to capture a single window and display it doubled in size.
# When run, the cursor changes to a crosshair.
# Click on the target window and the cursor will revert to normal.
#
[ -z ${DISPLAY} ] && echo "Requires X" && exit 1
which xwininfo > /dev/null
[ "$?" -ne 0 ] && exec popup "Requires xwininfo, see Xorg-7.(5 or 6)-bin.tcz" && exit 1
#
WINDOW_ID=`xwininfo -frame | grep " Window id:" | cut -d " " -f 4`
/bin/sh -c "imlib2_grab -id $WINDOW_ID /tmp/image.png"
/bin/sh -c "imlib2_view -s 2 /tmp/image.png"
Enlargement by two is much more than I need, but fractional values between 1 and 2 result in ragged distracting symbols. The imlib2 builtin algorithm is too crude to do a neat job on black and white .pngs using an enlargement factor like 1.3 say. Perhaps someone knows of a better algorithm, readily available or easily implemented ?
This simple modification of
Windowshot works well enough, but if the enlarged window is too big or you accidentally select the desktop, everything on the desktop is blanked out and the mouse is useless.
Another gem from Rich is a list of keyboard based window controls that I had stashed for just this moment.
CTL ALT - , (the minus close to P, not the one near the number-pad) reduces the height of the window.
One or two repeats make the top edge of the frame accessible, the mouse is now able to sort things out.
So I added some warnings and reminders. It took quite a while to find out how to get a popup to actually end up on top of everything else and even more time to have it appear only when really needed.
The display height comes from xdpyinfo while the target window height comes from xwininfo. Relying on the layout of these files to extract the numbers is not very robust but will do for now.
So we arrive at :
#!/bin/sh
# Based heavily on Tinycore's windowshot, this script captures a
# single window and displays it doubled in size. When run, the cursor
# changes to a crosshair and the target screen is selected by cilcking on it.
#
# The enlarged image can fill the display effectively disabling the mouse.
# To recover control, click on the image and use the Ctl Alt ' - ' key combination.
# This shrinks the the window and gives access to the top edge of the frame.
#
[ -z ${DISPLAY} ] && echo "Requires X" && exit 1
which xwininfo > /dev/null
[ "$?" -ne 0 ] && exec popup "Requires xwininfo, see Xorg-7.(5 or 6)-bin.tcz" && exit 1
HH=`xdpyinfo | grep dimensions: | cut -c 23-26`
#xdpyinfo | grep dimensions: | cut -d " " -f 4-7 | cut -d x -f 2
#
xwininfo -frame > data
WINDOW_ID=`grep " Window id:" data | cut -d " " -f 4`
H=`grep "Height:" data | cut -c 11-`; hh=$((2*H + 10))
#W=`grep "Width:" data | cut -c 10-`
/bin/sh -c "imlib2_grab -id $WINDOW_ID /tmp/image.png"
/bin/sh -c "imlib2_view -s 2 /tmp/image.png" &
sleep 0.1
if [ $hh -gt $HH ]; then popup "Click on image, then use 'Ctrl Alt - ' to access frame"; fi
No doubt the above can streamlined. This code is the result of trial and error on top of imitation.
I don't think the construction '/bin/sh -c " commands " ' is really needed in this context.
I read that the full version of Imlib2_view allows you to control the display window size and position but I guess
FLWM ignores the guidance so those parameters are absent in the TC version.
I think there is a way to use
Xmessage instead of
popup to give more convenient control of the magnifier in actual use.
Xmessage can have buttons that could allow a choice to close the mag session or magnify new content after scrolling the target. That is the next thing to do.
Once its working as I want, I'll submit an extension.
Sean