我正在使用 xmonad,并希望启用 UrgencyHook 功能,这样我就能知道何时有人用 pidgin 与我交谈。为此,我使用了模块XMonad.Hooks.UrgencyHook
。我使用 dzen2 和 conky 作为状态栏,我只想让 xmonad 在需要注意时突出显示 pidgin 所处的工作区。
现在我尝试使用 dzenUrgencyHook 并且它起作用了,但我实际上希望 xmonad 突出显示我弹出的当前 dzen2 栏中的工作区,这就是问题所在,因为什么都没有发生。
所以它看起来像是一个配置问题,因为 dzenUrgencyHook 工作时我假设 pidgin 实际上正在发送 WM_URGENT 信号。
这是我现在的配置:
-- ~/.xmonad/xmonad.hs
-- Imports {{{
import XMonad
-- Prompt
import XMonad.Prompt
import XMonad.Prompt.RunOrRaise (runOrRaisePrompt)
import XMonad.Prompt.AppendFile (appendFilePrompt)
-- Hooks
import XMonad.Operations
import System.IO
import System.Exit
import XMonad.Util.Run
import XMonad.Actions.CycleWS
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.SetWMName
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.UrgencyHook
import XMonad.Hooks.FadeInactive
import XMonad.Hooks.EwmhDesktops
import XMonad.Layout.NoBorders (smartBorders, noBorders)
import XMonad.Layout.PerWorkspace (onWorkspace, onWorkspaces)
import XMonad.Layout.Reflect (reflectHoriz)
import XMonad.Layout.IM
import XMonad.Layout.SimpleFloat
import XMonad.Layout.Spacing
import XMonad.Layout.ResizableTile
import XMonad.Layout.LayoutHints
import XMonad.Layout.LayoutModifier
import XMonad.Layout.Grid
import Data.Ratio ((%))
import qualified XMonad.StackSet as W
import qualified Data.Map as M
--}}}
-- Config {{{
-- Define Terminal
myTerminal = "gnome-terminal"
-- Define modMask
modMask' :: KeyMask
modMask' = mod4Mask
-- Define workspaces
myWorkspaces = ["1:main","2:web","3:vim","4:chat","5:music", "6:gimp", "7:misc"]
-- Dzen/Conky
myXmonadBar = "dzen2 -x '1440' -y '0' -h '24' -w '640' -ta 'l' -fg '#FFFFFF' -bg '#1B1D1E'"
myStatusBar = "conky -c /home/brafales/.xmonad/.conky_dzen | dzen2 -x '2080' -w '1040' -h '24' -ta 'r' -bg '#1B1D1E' -fg '#FFFFFF' -y '0'"
myBitmapsDir = "/home/brafales/.xmonad/dzen2"
--}}}
-- Main {{{
main = do
dzenLeftBar <- spawnPipe myXmonadBar
dzenRightBar <- spawnPipe myStatusBar
xmonad $ withUrgencyHook NoUrgencyHook $ defaultConfig
{ terminal = myTerminal
, workspaces = myWorkspaces
, keys = keys'
, modMask = modMask'
, layoutHook = layoutHook'
, manageHook = manageHook'
, logHook = myLogHook dzenLeftBar >> fadeInactiveLogHook 0xdddddddd
, normalBorderColor = colorNormalBorder
, focusedBorderColor = colorFocusedBorder
, borderWidth = 2
, startupHook = setWMName "LG3D"
}
--}}}
-- Hooks {{{
-- ManageHook {{{
manageHook' :: ManageHook
manageHook' = (composeAll . concat $
[ [resource =? r --> doIgnore | r <- myIgnores] -- ignore desktop
, [className =? c --> doShift "1:main" | c <- myDev ] -- move dev to main
, [className =? c --> doShift "2:web" | c <- myWebs ] -- move webs to main
, [className =? c --> doShift "3:vim" | c <- myVim ] -- move webs to main
, [className =? c --> doShift "4:chat" | c <- myChat ] -- move chat to chat
, [className =? c --> doShift "5:music" | c <- myMusic ] -- move music to music
, [className =? c --> doShift "6:gimp" | c <- myGimp ] -- move img to div
, [className =? c --> doCenterFloat | c <- myFloats ] -- float my floats
, [name =? n --> doCenterFloat | n <- myNames ] -- float my names
, [isFullscreen --> myDoFullFloat ]
])
where
role = stringProperty "WM_WINDOW_ROLE"
name = stringProperty "WM_NAME"
-- classnames
myFloats = ["Smplayer","MPlayer","VirtualBox","Xmessage","XFontSel","Downloads","Nm-connection-editor"]
myWebs = ["Firefox","Google-chrome","Chromium", "Chromium-browser"]
myMovie = ["Boxee","Trine"]
myMusic = ["Rhythmbox","Spotify"]
myChat = ["Pidgin","Buddy List"]
myGimp = ["Gimp"]
myDev = ["gnome-terminal"]
myVim = ["Gvim"]
-- resources
myIgnores = ["desktop","desktop_window","notify-osd","stalonetray","trayer"]
-- names
myNames = ["bashrun","Google Chrome Options","Chromium Options"]
-- a trick for fullscreen but stil allow focusing of other WSs
myDoFullFloat :: ManageHook
myDoFullFloat = doF W.focusDown <+> doFullFloat
-- }}}
layoutHook' = onWorkspaces ["1:main","5:music"] customLayout $
onWorkspaces ["6:gimp"] gimpLayout $
onWorkspaces ["4:chat"] imLayout $
customLayout2
--Bar
myLogHook :: Handle -> X ()
myLogHook h = dynamicLogWithPP $ defaultPP
{
ppCurrent = dzenColor "#ebac54" "#1B1D1E" . pad
, ppVisible = dzenColor "white" "#1B1D1E" . pad
, ppHidden = dzenColor "white" "#1B1D1E" . pad
, ppHiddenNoWindows = dzenColor "#7b7b7b" "#1B1D1E" . pad
, ppUrgent = dzenColor "black" "red" . pad
, ppWsSep = " "
, ppSep = " | "
, ppLayout = dzenColor "#ebac54" "#1B1D1E" .
(\x -> case x of
"ResizableTall" -> "^i(" ++ myBitmapsDir ++ "/tall.xbm)"
"Mirror ResizableTall" -> "^i(" ++ myBitmapsDir ++ "/mtall.xbm)"
"Full" -> "^i(" ++ myBitmapsDir ++ "/full.xbm)"
"Simple Float" -> "~"
_ -> x
)
, ppTitle = (" " ++) . dzenColor "white" "#1B1D1E" . dzenEscape
, ppOutput = hPutStrLn h
}
-- Layout
customLayout = avoidStruts $ tiled ||| Mirror tiled ||| Full ||| simpleFloat
where
tiled = ResizableTall 1 (2/100) (1/2) []
customLayout2 = avoidStruts $ Full ||| tiled ||| Mirror tiled ||| simpleFloat
where
tiled = ResizableTall 1 (2/100) (1/2) []
gimpLayout = avoidStruts $ withIM (0.11) (Role "gimp-toolbox") $
reflectHoriz $
withIM (0.15) (Role "gimp-dock") Full
imLayout = avoidStruts $ withIM (1%5) (And (ClassName "Pidgin") (Role "buddy_list")) Grid
--}}}
-- Theme {{{
-- Color names are easier to remember:
colorOrange = "#FD971F"
colorDarkGray = "#1B1D1E"
colorPink = "#F92672"
colorGreen = "#A6E22E"
colorBlue = "#66D9EF"
colorYellow = "#E6DB74"
colorWhite = "#CCCCC6"
colorNormalBorder = "#CCCCC6"
colorFocusedBorder = "#fd971f"
barFont = "terminus"
barXFont = "inconsolata:size=12"
xftFont = "xft: inconsolata-14"
--}}}
-- Prompt Config {{{
mXPConfig :: XPConfig
mXPConfig =
defaultXPConfig { font = barFont
, bgColor = colorDarkGray
, fgColor = colorGreen
, bgHLight = colorGreen
, fgHLight = colorDarkGray
, promptBorderWidth = 0
, height = 14
, historyFilter = deleteConsecutive
}
-- Run or Raise Menu
largeXPConfig :: XPConfig
largeXPConfig = mXPConfig
{ font = xftFont
, height = 22
}
-- }}}
-- Key mapping {{{
keys' conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
[ ((modMask, xK_p ), runOrRaisePrompt largeXPConfig)
, ((modMask .|. shiftMask, xK_Return ), spawn $ XMonad.terminal conf)
, ((modMask, xK_F2 ), spawn "gmrun")
, ((modMask .|. shiftMask, xK_c ), kill)
, ((modMask .|. shiftMask, xK_l ), spawn "slock")
-- Programs
, ((0, xK_Print ), spawn "scrot -e 'mv $f ~/screenshots/'")
, ((modMask, xK_o ), spawn "chromium-browser")
, ((modMask, xK_m ), spawn "nautilus --no-desktop --browser")
-- Media Keys
, ((0, 0x1008ff12 ), spawn "amixer -q sset Headphone toggle") -- XF86AudioMute
, ((0, 0x1008ff11 ), spawn "amixer -q sset Headphone 5%-") -- XF86AudioLowerVolume
, ((0, 0x1008ff13 ), spawn "amixer -q sset Headphone 5%+") -- XF86AudioRaiseVolume
, ((0, 0x1008ff14 ), spawn "rhythmbox-client --play-pause")
, ((0, 0x1008ff17 ), spawn "rhythmbox-client --next")
, ((0, 0x1008ff16 ), spawn "rhythmbox-client --previous")
-- layouts
, ((modMask, xK_space ), sendMessage NextLayout)
, ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) -- reset layout on current desktop to default
, ((modMask, xK_b ), sendMessage ToggleStruts)
, ((modMask, xK_n ), refresh)
, ((modMask, xK_Tab ), windows W.focusDown) -- move focus to next window
, ((modMask, xK_j ), windows W.focusDown)
, ((modMask, xK_k ), windows W.focusUp )
, ((modMask .|. shiftMask, xK_j ), windows W.swapDown) -- swap the focused window with the next window
, ((modMask .|. shiftMask, xK_k ), windows W.swapUp) -- swap the focused window with the previous window
, ((modMask, xK_Return ), windows W.swapMaster)
, ((modMask, xK_t ), withFocused $ windows . W.sink) -- Push window back into tiling
, ((modMask, xK_h ), sendMessage Shrink) -- %! Shrink a master area
, ((modMask, xK_l ), sendMessage Expand) -- %! Expand a master area
, ((modMask, xK_comma ), sendMessage (IncMasterN 1))
, ((modMask, xK_period ), sendMessage (IncMasterN (-1)))
-- workspaces
, ((modMask .|. controlMask, xK_Right ), nextWS)
, ((modMask .|. shiftMask, xK_Right ), shiftToNext)
, ((modMask .|. controlMask, xK_Left ), prevWS)
, ((modMask .|. shiftMask, xK_Left ), shiftToPrev)
-- quit, or restart
, ((modMask .|. shiftMask, xK_q ), io (exitWith ExitSuccess))
, ((modMask, xK_q ), spawn "killall conky dzen2 && && sleep 2 && /home/brafales/.cabal/bin/xmonad --recompile && /home/brafales/.cabal/bin/xmonad --restart")
]
++
-- mod-[1..9] %! Switch to workspace N
-- mod-shift-[1..9] %! Move client to workspace N
[((m .|. modMask, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
, (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
++
--
-- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
-- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
--
[((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
| (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
, (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
--}}}
-- vim:foldmethod=marker sw=4 sts=4 ts=4 tw=0 et ai nowrap
现在我希望“4:chat”(运行 pidgin 的地方)变为红色背景和黑色前景,但实际上什么也没发生。我想知道我做错了什么,因为我检查过类似的配置,显然是一样的。
我正在运行 xmonad 0.9.2
干杯!
答案1
问题在于,对于紧急工作区,ppUrgent
和ppHidden
都适用。由于您在 中使用了颜色格式ppHidden
,因此它将覆盖您可能添加到 的任何后续颜色ppUrgent
。
然而,这很容易解决;只需扩展ppUrgent
以删除适用的格式ppHidden
,使用以下dzenStrip
功能:
, ppUrgent = dzenColor "black" "red" . pad . dzenStrip
您的紧急挂钩应该可以正常运行。
作为补充,其他函数也可以应用于紧急工作区突出显示。例如,在我自己的 xmonad.hs 中,我应用了:
wrap ">" "<"
作为我的 ppUrgent 函数的一部分,从而产生如下的显示>1:im<
。
答案2
也许你可以尝试重定向输出并使用 dzen 标签处理颜色 StdoutUrgencyHook 听起来很有希望
我个人有
myUrgencyHook = withUrgencyHook dzenUrgencyHook
{ args = ["-x", "0", "-y", "184", "-h", "16", "-w", "320", "-ta ", "r", "-expand", "l", "-fg", "" ++ myUrgentFGColor ++ "", "-bg", "" ++ myNormalBGColor ++ "", "-fn", "" ++ myFont ++ ""] }
和
xmonad $ myUrgencyHook $ defaultConfig {
但从未测试过
答案3
你的问题是那一行:
xmonad $ withUrgencyHook NoUrgencyHook $ defaultConfig
将 NoUrgencyHook 更改为 dzenUrgencyHook ,或任何想要的http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-UrgencyHook.html 或者自己写:)