gpt4 book ai didi

haskell - 重启时XMonad确认

转载 作者:行者123 更新时间:2023-12-01 02:36:28 24 4
gpt4 key购买 nike

我是 Haskell 初学者,我正在使用 xmonad。我试图让它在退出之前提示我,因为我偶尔会不小心点击 mod+q。我找到了两种方法来做到这一点,但我一定是做错了什么,因为它们都不适合我:
https://bbs.archlinux.org/viewtopic.php?id=120298
http://comments.gmane.org/gmane.comp.lang.haskell.xmonad/11699

这是我的 xmonad.hs:

import XMonad
import XMonad.Config.Gnome
import XMonad.Actions.Plane
import XMonad.Util.EZConfig
import XMonad.Util.Run(spawnPipe)
import qualified Data.Map as M
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.UrgencyHook
import System.IO(Handle, hPutStrLn)
import System.Exit
import Control.Monad
import XMonad
import XMonad.Util.EZConfig
import XMonad.Util.Dmenu
import XMonad.Util.Run

workspaces' = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]

quit_confirm :: X ()
quit_confirm = do
let m = "confirm restart"
s <- dmenu [m]
when (m == s) (spawn "xmonad --restart")

conf_quit = do
response <- runProcessWithInput "dmenu" ["-p", "Quit?"] "yes\nno\n"
when (response == "yes") (spawn "xmonad --restart")

main = do
dzen2Pipe <- spawnPipe "dzen2 -w 1200 -xs 1 -ta l -fn '-*-terminus-*-*-*-*-16-*-*-*-*-*-*-*' -bg black -fg #d3d7cf "
dzen2Right <- spawnPipe "~/.xmonad/status-dzen.sh"
startupProgs <- spawnPipe "~/.xmonad/startups.sh"
xmonad $ defaultConfig
{
workspaces = workspaces'
, manageHook = manageHook' <+> manageHook defaultConfig
, modMask = mod4Mask
, terminal = "gnome-terminal"
, layoutHook = layoutHook'
, logHook = logHook' dzen2Pipe
}
`additionalKeysP`
[ -- Lock Screen
("M-S-l", spawn "gnome-screensaver-command -l")
-- Sleep
, ("M-S-;", spawn "gnome-screensaver-command -l; pmi action suspend")
-- wireless
, ("M-S-C-w", spawn "~/.xmonad/wireless.sh")
-- 1 screen reconf
, ("M-S-C-1", spawn "~/.xmonad/1-screen.sh")
-- 2 screen reconf
, ("M-S-C-2", spawn "~/.xmonad/2-screen.sh")
-- confirm for quit
, ("M-q", conf_quit)
]
`additionalKeys`
M.toList (planeKeys mod4Mask GConf Finite)

layoutHook' = avoidStruts $ layoutHook defaultConfig

logHook' = dynamicLogWithPP . dzenPP'

dzenPP' h = defaultPP
{
ppOutput = hPutStrLn h
}

manageHook' = composeAll
[ className =? "Pidgin" --> doShift "1" ,
className =? "Firefox" --> doShift "2" ,
className =? "Thunderbird" --> doShift "3" ,
className =? "OpenOffice.org 3.2" --> doShift "4",
manageDocks ]

谢谢!

编辑:显示菜单,但生成过程似乎不起作用。

最佳答案

其他人给出的答案错过了dmenu似乎在它返回的字符串末尾添加了一个额外的空格。您只需要执行以下操作,它对我有用:

confirm :: String -> X () -> X ()
confirm m f = do
result <- dmenu [m]
when (init result == m) f

然后,正如@mariop 建议的那样使用
confirm "Restart" $ spawn "xmonad --recompile && xmonad --restart"

或者
confirm "Exit" $ io (exitWith ExitSuccess)

关于haskell - 重启时XMonad确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9993966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com