|
楼主 |
发表于 2010-7-17 04:42:18
|
显示全部楼层
Debain菜单和程序菜单
我的配置原来也很短,功能是一天天加起来的。就越写越长了,本来是一个文件(是它的默认配置文件),后来就按功能分成好几个文件了。
这个菜单就比较夸张了,呵呵。fvwm最大的毛病是,那些菜单图标大的大小的小,有的没有,有的有,很不整齐,看着很难受。所以就写一些东西来生成菜单。菜单图标大小为22x22,用imagemagic改图标:
上酸菜:呵呵
首先是在主菜单上加两个菜单项:- #读取菜单文件:
- Read menudefs.hook Quiet
- Read AppMenu
- #添加Debian菜单(记得自己找图标配给菜单项):
- + "&Debian Menu%$[MenuIcon]/debian-logo.png%" Popup "/Debian"
- #添加普通的程序菜单,就是/usr/share/applications/*.desktop里的内容,别的桌面都有的,所以Fvwm也得加一个:
- + "&Applications%$[MenuIcon]/apps.png%" Popup "/Applications"
复制代码
FVWM的内置函数调用UpdateMenu,(可以在Run输入框里运行,或者自己定义一个菜单项/热键类):- DestroyFunc UpdateMenu
- AddtoFunc UpdateMenu
- + I Exec `touch /tmp/updatemenu;update-menus --menumethod ~/.fvwm/fvwm>/dev/null; ~/.fvwm/genmenu>/dev/null;rm /tmp/updatemenu`
- + I Schedule Periodic 500 12345 ReadMenu 12345
- DestroyFunc ReadMenu
- AddtoFunc ReadMenu
- + I Test (F /tmp/updatemenu) Break 1
- + I Schedule 100 Deschedule $0
- + I Read Menu
复制代码
Debian菜单的配置文件~/.fvwm/fvwm,名叫fvwm,保存在~/.fvwm里,这个好像要装menu才有update-menus这个命令。- #!/usr/bin/install-menu
- #I need menu-1.4!
- # arch-tag: 73ccd6e4-fcf8-4b3f-8672-f61ae101cab5
- compat="menu-1"
- !include menu.h
- !include lang.h
- outputencoding="LOCALE"
- function start($var,$com)=\
- "+ "" escfirst(esc(title(),"\\""),$hotkey,"&") \
- shell("~/.fvwm/createicon ""icon()"" "$com) "" " $var " " $com "\n"
- supported
- fvwmmodule= start("Module", $command)
- fvwmother= start("", $command)
- wm= start("Restart",$command)
- x11fvwm2= start("Exec exec", $command)
- x11fvwm= start("Exec exec", $command)
- x11= start("Exec exec", $command)
- text= start("Exec exec", term())
- endsupported
- # Usage:
- # Read /etc/X11/fvwm/menudefs.hook
- # Popup /Debian
- # Ok, "startmenu" is a little wacky, and comes in 4 parts:
- # 1. If this is running for a user, then we do a DestroyMenu to clear
- # out the system one. Furthermore, if we're dealing with the
- # top-level /Debian menu, then add a title for it (normally done in
- # system.fvwm2rc). Of course, none of this happens if we're
- # running as root to produce the system-wide menudef.hook file.
- # 2. We spit out an "AddToMenu /Foo/Bar/Baz" to start this menu.
- # 3. We add a trailing newline to the lot.
- startmenu= "DestroyMenu "" replacewith($section," ","_") ""\n" \
- "AddToMenu "" replacewith($section," ","_") "" "" \
- title() "" Title Top\n"
- endmenu= "\n"
- submenutitle= "+ "" escfirst(title(),$hotkey,"&") \
- shell("~/.fvwm/createicon ""icon()"" folder") "" Popup "" \
- replacewith($section," ","_") ""\n"
- genmenu= "menudefs.hook"
- rootprefix="/etc/X11/fvwm/"
- #Technical note: For historical reason, userprefix treat path starting
- #with 2 / as absolute and with 0 or one / as relative to $HOME. This
- #is why I added a / before the $
- #userprefix="/.fvwm/"
- userprefix=shell("echo -n /${FVWM_USERDIR-.fvwm}")
- treewalk="c(m)"
- mainmenutitle = "Debian Menu"
复制代码
生成程序菜单有脚本~/.fvwm/genmenu:- #!/bin/bash
- menutmp=/tmp/fvwmmenu
- tmpitem=$menutmp/item
- mkdir -p /tmp/fvwmmenu
- echo -n >$HOME/.fvwm/AppMenu
- catagories="System Office Network Utility Multimedia Game Graphics Setting Windows Other"
- for menu in $catagories
- do
- (echo "DestroyMenu "/Applications/$menu""
- echo "AddToMenu "/Applications/$menu" "$menu" Title Top") >$menutmp/$menu
- done
- for item in /usr/share/applications/*.desktop /usr/local/share/applications/*.desktop ~/.gnome2/vfolders/applications/*.desktop
- do
- if [ -f $item ]
- then
- grep -q "^NoDisplay=[Tt]rue" $item && continue
- iconv -f utf-8 -o $tmpitem "$item"
- exe="`sed -n "s/^Exec=//p" $tmpitem`"
- [ "$exe" == "" ] && continue
- exe="${exe#"}"
- exe="${exe%"}"
- exe="${exe% \%[uU]}"
- bexe="${exe#/}"
- if [ "$bexe" == "$exe" ]
- then
- exepath="`find -L ${PATH//:/ } -maxdepth 1 -type f -name ${exe%% *} 2>/dev/null`"
- elif [ -f ${exe%% *} ]
- then
- exepath="${exe%% *}"
- else
- echo $item>>missing
- continue
- fi
- [ "$exepath" == "" ] && echo $item>> missing && continue
- menu=Other
- for cata in $catagories
- do
- [ "$cata" == Multimedia ] && aa=Audio || aa=$cata
- grep -q "^Categories=.*$aa" $tmpitem&& menu=$cata && break
- done
- icon="`sed -n "s/^Icon=//p" $tmpitem`"
- name="`sed -n "s/^Name=//p" $tmpitem`"
- echo "+ "&$name`$HOME/.fvwm/createicon "$icon" $exe`" Exec exec $exe" >> $menutmp/$menu
- fi
- done
- appmenu="DestroyMenu "/Applications"
- AddToMenu "/Applications" "Applications" Title Top
- "
- for menu in $catagories
- do
- if ! tail -n 1 $menutmp/$menu |grep -q "^AddToMenu"
- then
- cat $menutmp/$menu >> $HOME/.fvwm/AppMenu
- echo >>$HOME/.fvwm/AppMenu
- appmenu=$appmenu"+ "&$menu`$HOME/.fvwm/createicon "$menu" "folder"`" Popup "/Applications/$menu"
- "
- fi
- done
- echo "$appmenu" >>$HOME/.fvwm/AppMenu
- rm -fr $menutmp
复制代码
查找并统一菜单图标大小的脚本$HOME/.fvwm/createicon:- #!/bin/bash
- sysicondir="/usr/share/pixmaps /usr/share/icons /usr/local/share/pixmaps /usr/local/share/icons"
- usricondir="$HOME/.icons"
- menuicondir="$HOME/.fvwm/icons/22x22/Menu"
- com="${2##*/}"
- if ! [ -s /tmp/updatemenu ]
- then
- find $sysicondir $usricondir -path "*16x16" -prune -o -type f -iname "*.*" -print > /tmp/updatemenu
- fi
- if [ "$1" == "" ]
- then
- icon=$com
- else
- icon="${1##*/}"
- icon="${icon%.*}"
- fi
- if ! [ -f "$menuicondir/$icon.png" ]
- then
- if [ -f "$1" ]
- then
- convert "$1" -resize 22x22 "$menuicondir/$icon.png"
- else
- file="`grep -F "${icon}." /tmp/updatemenu`"
- if [ "$file" == "" ]
- then
- [ "$com" != folder ] && echo -n %"$menuicondir/unknown.png"% || echo -n %"$menuicondir/folder.png"%
- exit
- fi
- file="${file%%
- *}"
- convert "$file" -resize 22x22 "$menuicondir/$icon.png"
- fi
- fi
- echo -n %"$menuicondir/$icon.png"%
复制代码 |
|