有人用ubuntu等很喜欢他的3D桌面,可我觉得xmonad,wmii之类WM更酷。我用ubuntu 7.10,以前用wmii,感觉不够好,主要是不能用盘移动浮动窗口,调整窗口大小。今年五一花了整整5天(我的黄金周啊)整了个xmonad,xmonad 7.10源里没有(8.04已经有了,直接可从源里装),下源码编译,还算顺利。装了xmonad,dzen2。可不知怎么把他加到登陆界面的选WM的选项里,网上搜了一大堆什么改.initrc什么的都不管用。折腾了好久才知道ubuntu是要在/usr/share/xsessions下新建个文件xmonad.desktop内容如下
引用:[Desktop Entry]
Encoding=UTF-8
Name=XMonad
Comment=Leightweight tiling window manager
Exec=xmonad
Icon=xmonad.png
Type=XSession
然后配置xmonad在~/.xmonad下新建xmonad.hs,我的配置文件(主要是键绑定)是这样的[code]import XMonad.Config (defaultConfig)
import XMonad.Layout.NoBorders
import XMonad.Hooks.DynamicLog
import XMonad.Actions.RotSlaves
import XMonad.Actions.FloatKeys
import Data.Bits
import XMonad.Layout.Circle
import XMonad.Actions.SinkAll
import XMonad.Layout.PerWorkspace
import XMonad.Layout.LayoutHints
import XMonad.Layout.Grid
import XMonad.Layout.Tabbed
import XMonad.Layout.Simplest
import XMonad.Util.Themes
import XMonad.Prompt
import XMonad.Prompt.Shell
--import XMonad.Layout.ToggleLayouts
import XMonad hiding ((|||))
import XMonad.Layout.LayoutCombinators ((|||))
import XMonad.Actions.CycleSelectedLayouts
import XMonad.Layout.ThreeColumns
import XMonad.Hooks.UrgencyHook
import XMonad.Util.Run (spawnPipe)
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import XMonad.Util.Run (spawnPipe)
import System.IO (hPutStrLn)
import XMonad.Actions.FocusNth
import Graphics.X11
myBitmapsDir = "/home/fjk/.share/icons/dzen"
myNormalBGColor = "#2e3436"
myFocusedBGColor = "#414141"
myNormalFGColor = "#babdb6"
myFocusedFGColor = "#73d216"
myUrgentFGColor = "#f57900"
myUrgentBGColor = myNormalBGColor
mySeperatorColor = "#2e3436"
myNormalBorderColor = "#003399"
myFocusedBorderColor = "#ff0055"
myWorkspaces = ["home", "web", "fun", "code"] ++ map show [5..9 :: Int]
statusBarCmd= "dzen2 -p -h 15 -ta l -bg '" ++ myNormalBGColor ++ "' -fg '" ++ myNormalFGColor ++ "'"
main :: IO ()
myKeys x =
[ ((modMask x , xK_a ), withFocused (keysMoveWindow(-30,0) ))
,((modMask x , xK_d ), withFocused (keysMoveWindow(30,0) ))
,((modMask x , xK_x ), withFocused (keysMoveWindow(0,30) ))
,((modMask x, xK_s ), withFocused (keysMoveWindow (0,-30)))
,((modMask x, xK_o ), withFocused (keysMoveWindowTo (1022,16) (1,0)))
,((modMask x .|. shiftMask, xK_o ), withFocused (keysMoveWindowTo (1022,765) (1,1)))
,((modMask x .|. shiftMask, xK_n ), withFocused (keysMoveWindowTo (0,765) (0,1)))
,((modMask x .|. shiftMask, xK_m ), withFocused (keysMoveWindowTo (0,16) (0,0)))
, ((modMask x .|. shiftMask, xK_i ), withFocused (keysResizeWindow (10,10) (0.5,0.5)))
, ((modMask x .|. shiftMask, xK_u ), withFocused (keysResizeWindow (0,-30) (0,0.5)))
, ((modMask x, xK_u ), withFocused (keysResizeWindow (0,30) (0,0.5)))
, ((modMask x .|. shiftMask, xK_d ), withFocused (keysResizeWindow (-10,-10) (0.5,0.5)))
, ((modMask x, xK_c ), withFocused (keysMoveWindowTo (512,384) (0.5,0.5)))
, ((modMask x, xK_g ), cycleThroughLayouts ["Grid"])
, ((modMask x , xK_v ), cycleThroughLayouts ["Tabbed Simplest"])
, ((modMask x .|. shiftMask, xK_t), sinkAll)
, ((modMask x , xK_f ), cycleThroughLayouts ["Full"])
, ((modMask x .|. controlMask , xK_space ), cycleThroughLayouts ["Tall"])
, ((modMask x , xK_x ), cycleThroughLayouts ["Circle"])
, ((modMask x .|. controlMask, xK_q), focusNth 0)
, ((modMask x .|. controlMask, xK_w), focusNth 1)
, ((modMask x .|. controlMask, xK_e), focusNth 2)
, ((modMask x .|. controlMask, xK_r), focusNth 3)
, ((modMask x .|. controlMask, xK_t), focusNth 4)
, ((modMask x .|. controlMask, xK_y), focusNth 5)
, ((modMask x .|. controlMask, xK_u), focusNth 6)
, ((modMask x .|. controlMask, xK_i), focusNth 7)
, ((modMask x .|. controlMask, xK_o), focusNth 8)
-- , ((modMask x .|. controlMask, xK_p), focusNth 9)
-- ,((numlockMask x, k), focusNth i) | (i, k) <- zip [0 .. 8] [xK_1 ..]
-- , ((modMask x .|. shiftMask, xK_p), shellPrompt defaultXPConfig)
]
-- mod4-[1..9] @@ Switch to window N
-- ++ [((numlockMask x, k), focusNth i)
-- | (i, k) <- zip [0 .. 8] [xK_1 ..]]
myTabConfig = defaultTheme {inactiveBorderColor = "#0000ff" ,inactiveTextColor = "#0000ff"
,activeBorderColor = "#666666" ,activeTextColor = "#ff0000"}
newKeys x = M.union (keys defaultConfig x) (M.fromList (myKeys x))
main = do
dzen2 <- spawnPipe statusBarCmd
xmonad defaultConfig
{ defaultGaps = [(15,0,0,0)]
, normalBorderColor =myNormalBorderColor
, focusedBorderColor = myFocusedBorderColor
, terminal = "urxvt"
,modMask = mod4Mask
-- ,numlockMask = mod3Mask
, logHook = dynamicLogWithPP $ defaultPP{
--ppTitle = shorten 160
-- , ppLayout = (>> "")
-- , ppOutput = hPutStrLn dzen2 }
ppCurrent = wrap ("^fg(" ++ myFocusedFGColor ++ ")^bg(" ++ myFocusedBGColor ++ ")^p(4)") "^p(4)^fg()^bg()",
ppUrgent = wrap ("^fg(" ++ myUrgentFGColor ++ ")^bg(" ++ myUrgentBGColor ++ ")^p(4)") "^p(4)^fg()^bg()",
ppVisible = wrap ("^fg(" ++ myNormalFGColor ++ ")^bg(" ++ myNormalBGColor ++ ")^p(4)") "^p(4)^fg()^bg()",
ppSep = "^fg(" ++ mySeperatorColor ++ ")^r(3x3)^fg()",
ppLayout = (\x -> case x of
"Tall" -> " ^i(" ++ myBitmapsDir ++ "/tall.xbm) "
-- "Grid" -> " ^i(" ++ myBitmapsDir ++ "/tall.xbm) "
-- "Full" -> " ^i(" ++ myBitmapsDir ++ "/tall.xbm) "
-- "Tall" -> " ^i(" ++ myBitmapsDir ++ "/tall.xbm) "
-- "Hinted Mirror Tall" -> " ^i(" ++ myBitmapsDir ++ "/tall.xbm) "
-- "Hinted Full" -> " ^i(" ++ myBitmapsDir ++ "/full.xbm) "
-- "Hinted ThreeCol" -> " ^i(" ++ myBitmapsDir ++ "/tall.xbm) "
_ -> " " ++ x ++ " "
),
ppTitle = wrap ("^fg(" ++ myFocusedFGColor ++ ")") "^fg()" ,
ppOutput = hPutStrLn dzen2
}
,workspaces = myWorkspaces
, manageHook = composeAll [ className =? "fontforge" --> doFloat,
className =? "MPlayer" --> doFloat,
className =? "Gimp" --> doFloat]
, layoutHook = smartBorders (tiled ||| Full ||| Grid ) ||| Circle ||| smartBorders(tabbed shrinkText myTabConfig)
-- ,layoutHook=layoutHints (tiled) ||| layoutHints (noBorders Full) ||| layoutHints (Mirror tiled) ||| layoutHints (Tall 1 (1/200) (1/2))
-- ,layoutHook=smartBorders(tiled ||| Full||| Mirror tiled ||| Tall 1(1/200)(1/2))
-- , keys = \c -> mykeys c `M.union` keys defaultConfig c
,keys=newKeys
}
where
-- tiled = ThreeCol 1 (1/100) (1/2)
tiled = Tall nmaster delta ratio
-- The default number of windows in the master pane
nmaster = 1
-- Default proportion of screen occupied by master pane
ratio = toRational (2/(1+sqrt(5)::Double)) -- golden
-- Percent of screen to increment by when resizing panes
delta = 0.02
-- mykeys (XConfig {modMask = modm}) = M.fromList $
-- [((modMask , xK_a ), withFocused (keysMoveWindow(-10,0) ))
-- ]
-- [ ((controlMask .|. modm, xK_Right), rotSlaves True)
-- , ((controlMask .|. modm, xK_Left), rotSlaves False) ]
一些信息用dzen2来显示,脚本如下
#!/bin/zsh -f
typeset -A DISKS
###
# Config
###
DATE_FORMAT="%d %b, %Y"
TIME_ZONES=("China/Hangzhou")
DISKS=(nickel /media/hda5 linux /)
SEPERATOR=' ^fg(#86AA3F)^c(3)^fg() '
BAR_BG='#7DA926'
BAR_FG='#B9D56E'
BAR_HH=6
BAR_HW=40
BAR_VH=12
BAR_VW=3
BAR_ARGS="-bg $BAR_BG -fg $BAR_FG -w $BAR_HW -h $BAR_HH"
ICON_DIR="$HOME/.share/icons/dzen"
NETWORK_INTERFACE=eth0
NET_DOWN_MAX=2000
NET_UP_MAX=1000
MAILDIR=~/mail/GmailMain
GLOBALIVAL=1
DATEIVAL=60
TIMEIVAL=1
DISKIVAL=1
#CPUTEMPIVAL=5
CPUIVAL=1
#NPIVAL=3
NETIVAL=1
###
# Functions
###
_date()
{
date +${DATE_FORMAT}
}
_time()
{
local zone
print_space=0
for zone in $TIME_ZONES; do
[[ $print_space -eq 1 ]] && print -n " "
print -n "${zone:t}: $(date '+%H:%M')"
print_space=1
done
}
#
# Format: label1 mountpoint1 label2 mountpoint2 ... labelN mountpointN
# Copied and modified from Rob
get_disk_usage() {
local rstr; local tstr; local i; local sep
for i in ${(k)DISKS}; do
tstr=$(print `df -h $DISKS[$i]|sed -ne 's/^.* \([0-9]*\)% .*/\1/p'` 100 | \
gdbar -h $BAR_HH -w $BAR_HW -fg $BAR_FG -bg $BAR_BG -l "${i}" -nonl | \
sed 's/[0-9]\+%//g;s/ / /g')
if [ ! -z "$rstr" ]; then
sep=${SEPERATOR}
fi
rstr="${rstr}${sep}${tstr}"
done
print -n $rstr
}
# Requires mesure
get_net_rates() {
local up;local down
up=`mesure -o $NETWORK_INTERFACE -l -K -c 2 -t`
down=`mesure -i $NETWORK_INTERFACE -l -K -c 2 -t`
# down=`echo 100`
# local up1; local up2; local down1; local down2
# down1=`mesure -i eth0 -K -c 2`
# down2=`mesure -i eth0 -K -c 2`
# down=`echo "$down2-$down1"`
# up1=`mesure -o eth0 -K -c 2`
# up2=`mesure -o eth0 -K -c 2`
# up=`echo "$up2-$up1"`
#echo "$down $up"
# echo "$down $up"
echo "$down"
echo "$up"
}
#cpu_temp()
#{
# print -n ${(@)$(#}
#
#np()
#{
# MAXPOS="100"
# CAPTION="^i(${ICON_DIR}/tall.xbm)"
# POS=`mpc | sed -ne 's/^.*(\([0-9]*\)%).*$/\1/p'`
# POSM="$POS $MAXPOS"
# print -n "$CAPTION"
# mpc | head -n1 | tr -d '\n'
# echo "$POSM" | gdbar -h 7 -w 50 -fg $BAR_FG -bg $BAR_BG
#}
cpu()
{
gcpubar -c 3 -bg $BAR_BG -fg $BAR_FG -w $BAR_HW -h $BAR_HH | tail -n1 | tr -d '\n'
}
#has_new_mail() {
# find ${MAILDIR}/*/new -not -type d | wc -l
#}
DATEI=0
TIMEI=0
DISKI=0
#NPI=0
#CPUTEMPI=0
CPUI=0
NETI=0
date=$(_date)
times=$(_time)
disk_usage=$(get_disk_usage)
#now_playing=$(np)
#temp=$(cpu_temp)
cpumeter=$(cpu)
net_rates=( `get_net_rates` )
while true; do
[[ $DATEI -ge $DATEIVAL ]] && date=$(_date) && DATEI=0
[[ $TIMEI -ge $TIMEIVAL ]] && times=$(_time) && TIMEI=0
[[ $DISKI -ge $DISKIVAL ]] && disk_usage=$(get_disk_usage) && DISKI=0
# [[ $NPI -ge $NPIVAL ]] && now_playing=$(np) && NPI=0
[[ $CPUI -ge $CPUIVAL ]] && cpumeter=$(cpu) && CPUI=0
#[[ $CPUTEMPI -ge $CPUTEMPIVAL ]] && temp=$(cpu_temp) && CPUTEMPI=0
[[ $NETI -ge $NETIVAL ]] && net_rates=( `get_net_rates` ) && NETI=0
# Disk usage
echo -n "${disk_usage}${SEPERATOR}"
echo -n "${cpumeter}${SEPERATOR}"
# Network
echo -n $net_rates[1] | gdbar -nonl -w $BAR_VW -h $BAR_VH -min 0 \
-max $NET_DOWN_MAX -fg $BAR_FG -bg $BAR_BG
# sed 's/[0-9]\+%//g;s/ //g'
#echo -n " "
echo -n $net_rates[2] | gdbar -nonl -w $BAR_VW -h $BAR_VH -min 0 \
-max $NET_UP_MAX -fg $BAR_FG -bg $BAR_BG
# sed 's/[0-9]\+%//g;s/ / /g'
echo -n "${SEPERATOR}"
# Mail notification
#if [ `has_new_mail` -gt 0 ]; then
# echo -n "^fg(#73d216)"
#fi
#echo -n "^i(${ICON_DIR}/envelope2.xbm)^fg()${SEPERATOR}"
# echo -n "{$now_playing}"
# Time and date
echo -n "${times}"
#echo -n "${date}"
echo
DATEI=$(($DATEI+1))
TIMEI=$(($TIMEI+1))
DISKI=$(($DISKI+1))
# NPI=$(($NPI+1))
CPUI=$(($CPUI+1))
#CPUTEMPI=$(($CPUTEMPI+1))
NETI=$(($NETI+1))
sleep $GLOBALIVAL
done[/code]不知道怎么进入xmonad时自动启动(进gnome不启动),就手工启动吧。