Page 1 of 4

gtk2desklet 3.1

Posted: Sun 11 Dec 2011, 18:47
by akash_rawal
This is a GTK module, which can turn many GTK based programs into a desktop app.

It is likely that the module may not succeed. Till now, I confirm gtkdialog, sylpheed, Xdialog, leafpad and thunar to be working.

You make the target program load the module by just passing an extra argument to the program:

Code: Select all

--gtk-module=gtk2desklet
e.g.

Code: Select all

gtkdialog3 --program=WIDGET --gtk-module=gtk2desklet
Hopefully, if the program is structured properly, the program's window will appear on the desktop, transparent, and without borders.

Download gtk2desklet-3.1.pet (15.9 KB)

Older versions here

Screenshots:
gtkdialog:
Image

gcolor2:
Image

Posted: Mon 12 Dec 2011, 17:01
by seaside
akash_rawal,

Nice program. In testing I got this result.
# gtkdialog-desklet --help
mktemp: invalid option -- -
Usage: mktemp [-V] | [-dqtu] [-p prefix] [template]
Also, I wasn't sure exactly how to run this program- could you post some examples... perhaps the one for the "desklet_example.png" that you listed.

Thanks,
s

Posted: Mon 12 Dec 2011, 17:04
by zigbert
Wonderful :D :D :D

Thanks a lot.
Would you become upset if I used this in Pwidgets ?


Sigmund

Posted: Mon 12 Dec 2011, 19:36
by 01micko
Just a tip :wink:

A useful option to the <button> tags with this mthod is reliief="2" has-focus="false"

More shortly...

..later

Try this crazy script! (it's a bit of fun :) , oh, and Pwidgets must be running)

Code: Select all

#!/bin/sh

WIDGETNAME=`basename $0`

#gif image to use (full path may be needed) 
#this is the gif we use, I don't know if I can distribute
#so if it's not there then we download it
#http://caccioppoli.com/Animations/Navidad/54.gif
#you can use any image but you need to change X and Y
[ ! -f file.gif ] && \
wget http://caccioppoli.com/Animations/Navidad/54.gif
[ "$?" -ne "0" ] && echo "failed" && exit
mv *.gif file.gif
if [ -s file.gif ];then echo "ok"
  else echo "woops, empty load, try again after ctrl/C"
  rm -f file.gif
  exit
fi

GIF=file.gif

#secreensize
SCREEN=`xwininfo -root | grep ' \-geometry ' | tr -s ' ' | cut -f 3 -d ' ' | cut -f 1 -d '+' | tr 'x' ' '`
HEIGHT=`echo -n "$SCREEN" | cut -f 2 -d ' '`
WIDTH=`echo -n "$SCREEN" | cut -f 1 -d ' '`

[ ! -d /tmp/santawidget ] && mkdir /tmp/santawidget #workdir
DESKBG=`cat /root/.config/wallpaper/bg_img`
resizepng "$DESKBG" /tmp/santawidget/background.png $WIDTH $HEIGHT 50 #resize and move bg
IMAGE=/tmp/santawidget/background.png #this is .png, makes life easier! It's the one we cut
NEWIMAGE=/tmp/santawidget/${WIDGETNAME}_background #this is the result
BGHEIGHT=`file $IMAGE| cut -d ' ' -f6|tr -d ','`
BGWIDTH=`file $IMAGE| cut -d ' ' -f4`
YDIMENSION=$(($BGHEIGHT - 400))    #  150 #`echo $(($HEIGHT - 300))` #hard code for demo
XDIMPRE1=$((${BGWIDTH} / 2))
XDIMPRE2=205
XDIMPRE3=$((${XDIMPRE1} + ${XDIMPRE2}))
XDIMENSION=$((${BGWIDTH} - ${XDIMPRE3}))
NEWIMAGEPATH=/tmp/santawidget #pixmap_path
IMAGEFILE=${WIDGETNAME}_background #_${WIDGETNAME} #our widget background

#REPLACE THESE dimensions if you use a different image file
#hard coded for demo 
#we can do a quick dummy run and get the info from xwininfo if geometry \
#is variable
X=410
Y=289

#code based on /usr/sbin/background_reshape BK
CROPLEFT=${XDIMENSION}
CROPTOP=${YDIMENSION}
#the magic #crop image using pamcut
pngtopnm $IMAGE | pamcut -left=${CROPLEFT} -top=${CROPTOP}  -height=$Y -width=$X | pnmtopng > $NEWIMAGE

#gtkrc ..our widget background, pseudo transparency
echo 'pixmap_path "'"$NEWIMAGEPATH"'"
style "'"${WIDGETNAME}-background"'"
{
   engine "pixmap"
   {
        image
        {
                function = FLAT_BOX
                file = "'"${IMAGEFILE}"'"
                border = {0, 0, 0, 0}
                detail = "base"
                stretch = FALSE
        }
   }
}
class "GtkWindow" style "'"${WIDGETNAME}-background"'"' >/tmp/gtkwidgetrc
export GTK2_RC_FILES=/tmp/gtkwidgetrc

export gui='<window title="'"${WIDGETNAME}"'" type-hint="7">
 <vbox>
  <pixmap>
   <input file>'"$GIF"'</input>
  </pixmap>
  <button has-focus="false" relief="2" tooltip-text="click to stop"> 
  </button>
 </vbox>
</window>'

gtkdialog -p gui -G  +${XDIMENSION}+${YDIMENSION} #${X}x${Y}

Posted: Tue 13 Dec 2011, 00:54
by seaside
01micko,

Nice tip and polished stars for the widget :idea:

Just a couple of corrections -
01micko wrote: wget http://caccioppoli.com/Animations/Navidad/54.gif && \
[ "$?" -ne "0" ] && echo "failed" && exit

BGWIDTH=`file $IMAGE| cut -d ' ' -f5`
Regards,
s

Posted: Tue 13 Dec 2011, 03:30
by puppyluvr
:D Hello,
I get as far as "OK"..
Then I get:
ok
./gtkdialog-desklets: line 53: pamcut: command not found
pnmtopng: Error reading magic number from Netpbm image stream. Most often, this means your input file is empty.

** (gtkdialog:3246): WARNING **: Pixbuf theme: Cannot load pixmap file /tmp/santawidget/gtkdialog-desklets_background: Image file '/tmp/santawidget/gtkdialog-desklets_background' contains no data


(gtkdialog:3246): GdkPixbuf-CRITICAL **: gdk_pixbuf_get_width: assertion `GDK_IS_PIXBUF (pixbuf)' failed
The part I colored red repeats till I hit ctrl-c to stop it...
Where do I get "pamcut"???

Posted: Tue 13 Dec 2011, 04:10
by 01micko
Thanks seaside, I was a bit sloppy :oops:

-

puppyluvr try pnmcut, I should have a test..

if [ `which pamcut` ];then CUT=pamcut
elif [ `which pnmcut` ];then CUT=pnmcut
else echo "sorry not cropping tool found" && exit
fi

obviously then you substitute pamcut with $CUT

Posted: Tue 13 Dec 2011, 04:24
by seaside
01micko wrote:Thanks seaside, I was a bit sloppy :oops:

-

puppyluvr try pnmcut, I should have a test..

if [ `which pamcut` ];then CUT=pamcut
elif [ `which pnmcut` ];then CUT=pnmcut
else echo "sorry not cropping tool found" && exit
fi

obviously then you substitute pamcut with $CUT
Yes, I forgot to mention that I put-
ln -s /usr/bin/pnmcut /usr/bin/pamcut
at the top of the script.

Also one other correction-
BGHEIGHT=`file $IMAGE| cut -d ' ' -f7|tr -d ','`

I get the same pix errors, but it runs anyway....

Regards,
s

Posted: Tue 13 Dec 2011, 05:51
by puppyluvr
:D Hello,
Works now...
Tried a few different images..

2 questions:
1. Why does pwidgets have to be running...?
2. Which part controls screen location..? I cant seem to find it.. :oops:

Posted: Tue 13 Dec 2011, 11:59
by 01micko
puppyluvr wrote::D Hello,
Works now...
Tried a few different images..

2 questions:
1. Why does pwidgets have to be running...?
2. Which part controls screen location..? I cant seem to find it.. :oops:
Answers
1) It doesn't, but you do need resizepng from pwidgets, actually it's a MU proggy, or you could change it to vovchik's bacon version.. I forget the name. I was a bit hasty in posting this morning!
2) XDIMENSION and YDIMENSION

Actually, I just had a moment to look at the code, I changed the file.gif test to an if statement, easier for me to fit in more!

Thanks to akash_rawal's work for the inspiration :)

Code: Select all

#!/bin/sh

WIDGETNAME=`basename $0`

#gif image to use (full path may be needed)
#this is the gif we use, I don't know if I can distribute
#so if it's not there then we download it
#http://caccioppoli.com/Animations/Navidad/54.gif
#you can use any image but you need to change X and Y
if [ ! -f file.gif ];then
  wget http://caccioppoli.com/Animations/Navidad/54.gif
    if [ "$?" -ne "0" ];then 
     echo "failed" && exit
      else mv *.gif file.gif
    fi
fi
if [ -s file.gif ];then echo "ok"
  else echo "woops, empty load, try again after ctrl/C"
  rm -f file.gif
  exit
fi

GIF=file.gif

#secreensize
SCREEN=`xwininfo -root | grep ' \-geometry ' | tr -s ' ' | cut -f 3 -d ' ' | cut -f 1 -d '+' | tr 'x' ' '`
HEIGHT=`echo -n "$SCREEN" | cut -f 2 -d ' '`
WIDTH=`echo -n "$SCREEN" | cut -f 1 -d ' '`

[ ! -d /tmp/santawidget ] && mkdir /tmp/santawidget #workdir
if [ -f /root/.config/wallpaper/bg_img ];then DESKBG=`cat /root/.config/wallpaper/bg_img`
  else DESKBG=/usr/share/backgrounds/default.jpg
fi
resizepng "$DESKBG" /tmp/santawidget/background.png $WIDTH $HEIGHT 50 #resize and move bg
IMAGE=/tmp/santawidget/background.png #this is .png, makes life easier! It's the one we cut
NEWIMAGE=/tmp/santawidget/${WIDGETNAME}_background #this is the result
BGHEIGHT=`file $IMAGE| cut -d ' ' -f6|tr -d ','`
BGWIDTH=`file $IMAGE| cut -d ' ' -f4`
YDIMENSION=$(($BGHEIGHT - 400))    #  150 #`echo $(($HEIGHT - 300))` #hard code for demo
XDIMPRE1=$((${BGWIDTH} / 2))
XDIMPRE2=205
XDIMPRE3=$((${XDIMPRE1} + ${XDIMPRE2}))
XDIMENSION=$((${BGWIDTH} - ${XDIMPRE3}))
NEWIMAGEPATH=/tmp/santawidget #pixmap_path
IMAGEFILE=${WIDGETNAME}_background #_${WIDGETNAME} #our widget background

#REPLACE THESE dimensions if you use a different image file
#hard coded for demo
#we can do a quick dummy run and get the info from xwininfo if geometry \
#is variable
X=410
Y=289

#code based on /usr/sbin/background_reshape BK
CROPLEFT=${XDIMENSION}
CROPTOP=${YDIMENSION}
#the magic #crop image using pamcut
if [ `which pamcut` ];then CUT=pamcut
  elif [ `which pnmcut` ];then CUT=pnmcut
  else echo "sorry no cropping tool found" && exit
fi 
pngtopnm $IMAGE | $CUT -left=${CROPLEFT} -top=${CROPTOP}  -height=$Y -width=$X | pnmtopng > $NEWIMAGE

#gtkrc ..our widget background, pseudo transparency
echo 'pixmap_path "'"$NEWIMAGEPATH"'"
style "'"${WIDGETNAME}-background"'"
{
   engine "pixmap"
   {
        image
        {
                function = FLAT_BOX
                file = "'"${IMAGEFILE}"'"
                border = {0, 0, 0, 0}
                detail = "base"
                stretch = FALSE
        }
   }
}
class "GtkWindow" style "'"${WIDGETNAME}-background"'"' >/tmp/gtkwidgetrc
export GTK2_RC_FILES=/tmp/gtkwidgetrc

export gui='<window title="'"${WIDGETNAME}"'" type-hint="7">
 <vbox>
  <pixmap>
   <input file>'"$GIF"'</input>
  </pixmap>
  <button has-focus="false" relief="2" tooltip-text="click to stop">
  </button>
 </vbox>
</window>'

gtkdialog -p gui -G  +${XDIMENSION}+${YDIMENSION} #${X}x${Y} 

Posted: Fri 23 Dec 2011, 19:02
by akash_rawal
Sorry for responding late.

Upgraded to version 1.0
Changelog:
  • Now using gdk-pixbuf library instead of pnmcut, transparency is now displayed much faster.
  • Now using JPEG format instead of PNG, much faster.
  • Several compatibility issues fixed.
  • Help and examples added at /usr/share/doc/gtkdialog-desklet
  • Response to wallpaper change has been improved significantly.
_________________________________________________________
zigbert wrote: Thanks a lot.
Would you become upset if I used this in Pwidgets ?
Not at all :!:
You may use it the way you want.
________________________________________________________
seaside wrote: Nice program. In testing I got this result.

Code: Select all

# gtkdialog-desklet --help 
mktemp: invalid option -- - 
Usage: mktemp [-V] | [-dqtu] [-p prefix] [template] 
I observed this issue in Puppy 430. This issue has been fixed in version 1.0 .
In addition, I observe another issue.
type-hint="7" tag isn't working in 430.
Seems to be a problem in GTK.

Posted: Sat 24 Dec 2011, 02:13
by 01micko
akash_rawal

Nice!

I made a useful widget... I have more too, will post later when I fine tune them.

Code: Select all

#!/bin/sh
#named "ramGTK"
WIDGETNAME=`basename $0`

export TOTRAM=`free -m|grep ^Mem|awk '{print $2}'`
freeramfunc(){
while [ 1 ]; do 
USEDRAM=`free -m|grep ^Mem|awk '{print $3}'`
FREERAM=`free -m|grep ^Mem|awk '{print $4}'`
echo $(($USEDRAM * 100 / $TOTRAM))
echo "RAM $FREERAM MB"
sleep 1 
continue
done
}

export -f freeramfunc

export ramwidget="<hbox>
  <progressbar width-request=\"140\" height-request=\"14\" tooltip-text=\"showing free RAM of total $TOTRAM\">
   <input>freeramfunc</input>
  </progressbar>
 </hbox>"
gtkdialog-desklet -p ramwidget -c



Posted: Sat 24 Dec 2011, 03:51
by Flash
Doesn't this belong in the Desktop section of Additional Software? :?

Posted: Sat 24 Dec 2011, 04:56
by akash_rawal
01micko wrote: I made a useful widget...
Great widget, but I had to make some modifications to make it work on lucid puppy 511.

Portability issues are always a headache. If only there was a thread dealing with writing portable shell scripts.

Code: Select all

#!/bin/sh 
#named "ramGTK" 
WIDGETNAME=`basename $0` 

export TOTRAM=`free|grep Mem|awk '{print $2}'` #Removed '-m' option
freeramfunc(){ 
while [ 1 ]; do 
USEDRAM=`free|grep Mem|awk '{print $3}'` #Removed '-m' option
FREERAM=`free|grep Mem|awk '{print $4}'`#Removed '-m' option 
echo $(($USEDRAM * 100 / $TOTRAM)) 
echo "RAM $FREERAM MB" 
sleep 1 
continue 
done 
} 

export -f freeramfunc 

export ramwidget="<hbox> 
  <progressbar width-request="140" height-request="14" tooltip-text="showing free RAM of total $TOTRAM"> 
   <input>freeramfunc</input> 
  </progressbar> 
 </hbox>" 
gtkdialog-desklet -p ramwidget -c

________________________________________________
Flash wrote: Doesn't this belong in the Desktop section of Additional Software?
It may, but this is not a full widget platform. It's a way to write programs, just like gtkdialog.

Posted: Sat 24 Dec 2011, 08:36
by Lobster
Thanks to akash_rawal's work for the inspiration
It's like Christmas . . . wait a minute it is Christmas . . .

Thanks guys - Mick I had to move resizepng to the bin directory (remembering to right click on it and change permissions to make runnable)

What fun. Will we be seeing its use in Slacko 5.3.2, or in Saluki 004 I wonder . . .

:)

Posted: Sat 24 Dec 2011, 21:40
by seaside
akash_rawal,

Very nice update and thanks especially for the examples section.

I tried an upgrade to Gtk2.16 on pup431 to see if the
type-hint="7" would work then, but it failed there as well.

Since a similar window behaviour can be made by using the <window decorated="false"> tag, is there a way to change
gtkdialog-desklet to allow a window tag?

Thanks again and the operation seems much faster now.

Regards,
s

Upgraded to version 1.1

Posted: Sun 25 Dec 2011, 18:51
by akash_rawal
Upgraded to version 1.1
Changelog:
  • Added a few workarounds for older puppies (still not perfect)
  • Added ability to stretch given background image
  • Added ability to restart gtkdialog
  • Added facility to refresh GTK theme and transparency
  • added optimisation workaround for apps that resize very often
  • Transparency is now enabled for XFCE (Please test)
___________________________________________
seaside wrote: I tried an upgrade to Gtk2.16 on pup431 to see if the
type-hint="7" would work then, but it failed there as well.

Since a similar window behaviour can be made by using the <window decorated="false"> tag, is there a way to change
gtkdialog-desklet to allow a window tag?
Now I am using:

Code: Select all

<window type-hint="7" decorated="false" skip-taskbar-hint="true" skip-pager-hint="true">
Still this is not working to my expectations. Apps appear only on one desktop, raise over other windows when clicked and can be dragged by [Alt] + Drag.

I am purposefully not allowing <window> tag as this can interfere with transparency if gtkdialog is restarted, if user provides option window_position=2 to bring the app under mouse. An alternative is given in the help file as well as in examples.

Anyways Lucid Puppy 511 that I use uses GTK 2.20.

Posted: Sun 25 Dec 2011, 21:55
by 01micko
Hi akash_rawal

I updated to your gtkdialog-desklet-1.1 but I have a problem with wallpaper-server apparent in v-1.0 too. This occurs in Lupu-528-004 and Slacko-5.3.1.(more info down the page and in screen shot)

I updated my ram desklet to detect if free -m can be used and if not default to just free. This overcomes your little issue of earlier and makes the desklet backward compatible. I also added screen positioning capability, but I did not write a "help" for it as it's designed to be called from a script. The default position is "R" wich is 280px from right of screen Passed params include "L" for 30px from left, any integer within your screen height which is the Y axis, or X(any integer inside your screen width) for custom X axis placement. It's very simple code from a simple coder!

The problem is that transparency is lost if the X dimension exceeds approxiamately three quarters of screen width. I tried on different resolutions (different machines) and the ratio is different on 1024x768 it is exactly 0.7451171875 every time (763px) and on 1280x1024 it is exactly 0.79609375 (1019px). I don't know if these measurements will be of any help in debugging.

There is also an error message:

Code: Select all

(wallpaper-server:11193): GdkPixbuf-CRITICAL **: gdk_pixbuf_new_subpixbuf: assertion `src_x >= 0 && src_x  + width <= src_pixbuf=>width' failed
(see screeny)

Any ideas?

Thanks

New ramGTK code:

Code: Select all

#!/bin/sh
#named "ramGTK"
#set -x
WIDGETNAME=`basename $0`

#geometry is a passed parram
X=R
Y=100
while [ $# != 0 ];do
I=1
	while [ $I -lt `echo $# | wc -c` ]; do
		case $1 in
			L)	X=L ;;
			R)  X=R ;;
			[0-9]*[0-9]) Y=$1 ;;
			X*[0-9]) X=`echo $1|tr -d 'X'` ;;
		esac
		shift
		I=$(($I+1))
	done
done

#screensize
SCREEN=`xwininfo -root | grep ' \-geometry ' | tr -s ' ' | cut -f 3 -d ' ' | cut -f 1 -d '+' | tr 'x' ' '`
HEIGHT=`echo -n "$SCREEN" | cut -f 2 -d ' '`
WIDTH=`echo -n "$SCREEN" | cut -f 1 -d ' '`

case $X in
L) XDIM=30 ;;
R) XDIM=$(( $WIDTH - 220 )) ;;
*) XDIM=$X ;;
esac
YDIM=$Y

echo "$XDIM $YDIM"

#hack for older "free"
free -m >/dev/null 2>&1
[ $? = 0 ] && export FREE="free -m" U=M || export FREE="free" U=K

#calc free ram
export TOTRAM=`$FREE|grep -w Mem|awk '{print $2}'`
freeramfunc(){
while [ 1 ]; do 
USEDRAM=`$FREE|grep -w Mem|awk '{print $3}'`
FREERAM=`$FREE|grep -w Mem|awk '{print $4}'`
echo $(( $USEDRAM * 100 / $TOTRAM ))
echo "RAM $FREERAM $U"
sleep 1 
continue
done
}

export -f freeramfunc

#gui
export ramwidget="<hbox>
  <progressbar width-request=\"140\" height-request=\"14\" tooltip-text=\"showing free RAM of total $TOTRAM $U\">
   <input>freeramfunc</input>
  </progressbar>
 </hbox>"
eval $(gtkdialog-desklet -p ramwidget --geometry=+${XDIM}+${YDIM})

This code is not great as even doing ctrl-c it still runs :?

Re: gtkdialog-desklet

Posted: Wed 28 Dec 2011, 15:14
by recobayu
i'm sorry, can someone give me the mirror?
i can't download that link
i think this gtkdialog-desklet very nice
:D

Upgraded to version 1.2

Posted: Fri 30 Dec 2011, 16:56
by akash_rawal
Upgraded to version 1.2
Changelog:
  • Now using X11 library to determine wallpaper, transparency is supported for many DEs.
  • Fixed communication problems by simply removing wallpaper-server
    (wallpaper-server existed for performance reasons, but now wallpaper can be fetched from X server without performance issues.)
  • Fixed window geometry when desklet is near bottom-right corner or partially offscreen. (Thanks 01micko)
  • Fixed the problem that gtkdialog-desklet was not exiting by Ctrl+c
__________________________________________________
01micko wrote: The problem is that transparency is lost if the X dimension exceeds approxiamately three quarters of screen width.
I traced the problem to xwininfo which gives negative values for geometry when a window is close to bottom right corner.

Now I am using my own program create-bg which uses X11 to fetch background image portion for a given window. How to use that is given in gtkdialog-desklet help file, in Hidden features section.