# Desktop icons for the mounted partition(s) and for $HOME.
# This add Thunar sipport in Fvwm-Crystal.
# Written by Dominique Michel <dominique_libre@users.sourceforge.net>, 2010-2013
# for Fvwm-Crystal.
#
# From Fvwm FAQ, 7.13 with huge modifications and added functions.
# This file will scan /etc/mtab, find the mounted drive(s) or partition(s),
# and create the icons on the desktop corresponding to your home directory and
# to the drives. At that time, the only action associated to the icons
# is to launch Thunar into the corresponding mount point. 
# You can also move the icons, but the moves will not survive a restart.
# The icons are like in the AmigaOS with 2 different pictures.
#
# Requirement: gawk, sort, Thunar, and Fvwm.
# In order to use it, add
# 
# Test (x thunar) PipeRead 'pidof rox 1>/dev/null || pidof nautilus 1>/dev/null || echo "Include components/functions/Icon-Launcher"'
#
# into some recipe after "Include Icon-Amiga" or "Include Icon-Thumbnails". I added almost
# all the icon styles here, so maybe this will work fine without one of those includes.

PipeRead 'echo "Style * IconBox $(($[vp.width]-36))x$(($[vp.height]-92))+18+46, IconFill top left, IconGrid 50 50"'

DestroyFunc Icon-Launch-CurrentDesk
AddToFunc Icon-Launch-CurrentDesk
+ C X thunar $0
+ M Move
+ C FlipFocus
+ C Raise

# FvwmButtons icon launcher. It start iconic
# Syntax: Launcher name icon
# Examples:
# Launcher Home home.xpm
DestroyFunc Launcher
AddToFunc Launcher
+ I KillModule FvwmButtons $0
+ I DestroyModuleConfig $0: *
+ I *$0: Font "xft:$[panel_font]"
+ I *$0: (1x1+0+0)
+ I All ($0) Layer 0 2
+ I Module FvwmButtons $0
+ I Module FvwmAuto 10 -menter "Change-Icon $0 $1" "Restore-Icon $0 $1"
+ I Style $0 UseStyle *
+ I Style $0 Icon $1, StartIconic, StartsLowered, !Handles, VariablePosition, BorderWidth 0, !Borders, ParentalRelativity, IconTitle, IconTitleColorset $[infostore.cs_menu_active], HilightIconTitleColorset $[infostore.cs_menu_active], IconTitleFormat %n, IconBackgroundColorset $[infostore.cs_icon_inactive], IconBackgroundColorset $[infostore.cs_icon_inactive], IconTitleRelief 0, IconBackgroundRelief 0, IconBackgroundRelief 0, IconFont "xft:$[title_font]:pixelsize=$[title_font_size]:$[title_font_style]", StickyIcon,!StickyStippledIconTitle 

DestroyFunc Change-Icon
AddToFunc Change-Icon
+ I ThisWindow ($0) Schedule 10 Style $0 Icon $1.active.png

DestroyFunc Restore-Icon
AddToFunc Restore-Icon
+ I ThisWindow ($0) Style $0 Icon $1

# Wrapper function
DestroyFunc Generate-Icons
AddToFunc Generate-Icons
+ I Style * NoIcon
+ I Make-Icons
+ I Style * !NoIcon

# which drives are mounted into the system
DestroyFunc Make-Icons
AddToFunc Make-Icons
+ I PipeRead "gawk \'/^\\/dev\\// { print $$$2; }\' </proc/mounts |sort > /tmp/Icon-Drives"
# Root
#+ I PipeRead 'Root="/"; echo "Launcher Root 48x48/categories/Boing_4.png"; \
#	echo "All (Root) Layer 0 0"; \
#	echo "Mouse (Root) 1 I $[Mod] Icon-Launch-CurrentDesk /"'
#	echo "Mouse (Root) 2 I $[Mod] Generate-Icons /"'
#+ I Wait Root
# Home
+ I PipeRead 'LocalUser=`id -un`; echo "Launcher Home 48x48/categories/Home.png"; \
	echo "All (Home) Layer 0 0"; \
	echo "Mouse (Home) 1 I $[Mod] Icon-Launch-CurrentDesk /home/`id -un`"'
+ I Wait Home
# Make the icons
# The drives
# If you want all the mounted partitions, comment the #Root section in this function.
# Uncomment also what follow to the end of this function.
# You may want to comment the #Home function if it is on its own partition.
+ I PipeRead 'i=2; m=$((((2*(($[panel_font_size]+56))))-32)); j=$m; while read line; do \
      if [[ "${line}" == "/" ]]; \
      then echo "Launcher ${line} 48x48/categories/Boing_4.png"; \
      else echo "Launcher ${line} 48x48/categories/Work_4.png"; \
      fi ; \
      echo "Mouse (${line}) 1 I $[Mod] Icon-Launch-CurrentDesk ${line}"; \
      echo "Wait ${line}"; \
      j=$(($i*$m)); i=$(($i+1)); \
done </tmp/Icon-Drives'
+ I PipeRead "rm /tmp/Icon-Drives"

# Do something now !
# The partitions must be first
#Style * NoIcon
# Make the icons
#Make-Icons
# We want the other icons
#Style * !NoIcon
Generate-Icons
# vim:ft=fvwm
