2012-04-03 13 views
4

Ich bin ein Haskell Anfänger und ich benutze xmonad. Ich versuche, mich dazu zu bringen, bevor ich aufhöre, da ich gelegentlich zufällig mod + q treffe. Ich habe zwei Möglichkeiten gefunden, das zu tun, aber ich muss etwas falsch machen, weil keiner von beiden für mich funktioniert: http://comments.gmane.org/gmane.comp.lang.haskell.xmonad/11699XMonad Bestätigung beim Neustart

Hier ist mein 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 ] 

Dank!

Bearbeiten: Das Menü wird angezeigt, aber der Spawn-Prozess scheint nicht zu funktionieren.

+0

Sie nannte es 'conf_quit', aber es macht einen Neustart. Möchten Sie, dass es nach einer erfolgreichen Bestätigung beendet oder neu gestartet wird? –

+0

Ich ging durch beide, aber es führt den Spawn-Prozess nicht durch. Ich fange an zu denken, dass mein Problem von woanders kommt, da der Code für andere Leute funktioniert. –

+0

Was genau passiert? Was lässt dich denken, dass der 'Spawn' nicht passiert? Was passiert, wenn Sie den Schlüssel an etwas binden, das offensichtlicher ist als ein Spawn? Kannst du überprüfen, ob deine xmonad ausführbare Datei in xmonads 'PATH' ist (was sich von dem' PATH' deines Terminals und dem 'PATH' deiner Konsole unterscheiden kann)? –

Antwort

2

Die Antworten, die andere gab verpasst, dass dmenu ein hinzuzufügen scheint zusätzliches Leerzeichen bis zum Ende der zurückgegebenen Zeichenfolge. Sie müssen nur Folgendes tun und es funktioniert für mich:

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

Und dann, als @mariop Verwendung entweder

confirm "Restart" $ spawn "xmonad --recompile && xmonad --restart" 
vorgeschlagen

oder

confirm "Exit" $ io (exitWith ExitSuccess) 
0

Sie sagen, Sie möchten einen quit bestätigen, aber Ihr Code bestätigt einen Neustart. Wenn dies Neustart ist, den Sie möchten, habe ich getestet und quit_confirm funktioniert.

Was Sie wahrscheinlich verpassen, ist die Neukompilierung von xmonad, um Ihre neue Konfiguration zu sehen. Try this:

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

Hallo. Leider hat es nicht funktioniert. Das Menü wird angezeigt, scheint jedoch den Spawnprozess nicht auszuführen. Ich denke, dass es ein Haken sein könnte, den ich verpasst habe oder eine Fehlkonfiguration. –

+0

Versuchen Sie etwas anderes zu laichen, das Sie kennen, funktioniert wie wireless.sh. –

+0

Es ist das gleiche und.xsession-errors scheint nichts Nützliches darin zu haben. –

1

Ändern Sie den Schlüssel Bindung an

("M-q", confirm "Confirm restart?" $ restart "xmonad" True) 

Und eine allgemeine Bestätigung Aktion hinzufügen, die dmenu verwendet

confirm :: String -> X() -> X() 
confirm msg f = do 
    a <- dmenu [msg,"y","n"] 
    when (a=="y") f 
+0

Hallo, ich habe es versucht, aber immer noch nicht funktioniert. Das Menü wird angezeigt, aber das scheint nicht ausgeführt zu werden und ich finde nichts Relevantes in meinem .xsession-errors –

+0

Ich hatte manchmal Probleme beim Versuch xmonad neu zu starten und die Lösung bestand darin, die X-Sitzung neu zu starten Xmonad neu laden (zB gdm neu starten). Jetzt habe ich selbst versucht und mein Code arbeitet an xmonad 0.10-2 (Debian-Paket). – mariop

0

ich das folgende Modul geschrieben, die nicht dmenu installiert werden muss:

----------------------------------------------------------------------------- 
-- | 
-- Module  : XMonad.Prompt 
-- Copyright : (C) 2015 Antoine Beaupré 
-- License  : BSD3 
-- 
-- Maintainer : Antoine Beaupré <[email protected]> 
-- Stability : unstable 
-- Portability : unportable 
-- 
-- A module for setting up simple confirmation prompts for keybindings. 
-- 
----------------------------------------------------------------------------- 
module XMonad.Prompt.ConfirmPrompt (confirmPrompt 
            -- * Usage 
            -- $usage 
            , module XMonad.Prompt 
            -- * Use case: confirming exit 
            -- $tip 
            , EnterPrompt 
            ) where 

import XMonad (X) 
import XMonad.Prompt (XPConfig, XPrompt, showXPrompt, mkXPrompt, mkComplFunFromList) 

{- $usage 

This module makes it easy to add a confirmation prompt for specific 
actions. Instead of just running the action, a simple confirmation 
prompt will be created using 'XMonad.Prompt' primitives. The action 
will then run normally if the user confirms. 
-} 

{- $tip 
This should be used something like this: 

> ... 
> , ((modm , xK_l), confirmPrompt defaultXPConfig "exit" $ io (exitWith ExitSuccess)) 
> ... 
-} 

{- | Customized 'XPrompt' prompt that will ask to confirm the given string -} 
data EnterPrompt = EnterPrompt String 
instance XPrompt EnterPrompt where 
    showXPrompt (EnterPrompt n) = "Confirm " ++ n ++ " (esc/ENTER)" 

{- | Prompt the user to confirm a given action. We offer no completion 
    and simply ask to confirm (ENTER) or cancel (ESCAPE). The actual key 
    handling is done by mkXPrompt.-} 
confirmPrompt :: XPConfig -> String -> X() -> X() 
confirmPrompt config app func = mkXPrompt (EnterPrompt app) config (mkComplFunFromList []) $ const func 

Installieren Sie diese in einem ~/.xmonad/lib/XMonad/Prompt Verzeichnis und genießen Sie!

(I submitted dies auf die XMonad Mailing-Liste und ich bin für Feedback warten ...)