You are not logged in.

#1 2011-06-05 18:20:51

codemon
Member
From: India
Registered: 2009-12-08
Posts: 12
Website

[SOLVED] Make xmonad show confirmation on mod-shift-q

Hi,

While using xmonad, sometimes, I accidentally press mod-shift-q instead of mod-shift-c. So instead of closing a window, I end up staring at a blinking cursor.

Is there any way to show a confirmation dialog when I press mod-shift-q? I'm not familiar with Haskell and I find the syntax of the configuration file a bit hard to follow. Here's what it looks like right now:

import XMonad
import XMonad.Layout.NoBorders
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.SetWMName
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.FadeInactive
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO

myManageHook = composeAll
    [ className =? "Gimp"      --> doFloat    
    ]

main = do
     xmproc <- spawnPipe "xmobar"
     xmonad $ defaultConfig
         { modMask = mod4Mask
     , startupHook = setWMName "LG3D"
     ,  borderWidth        = 2
     , terminal           = "urxvt"
     , normalBorderColor  = "#cccccc"
     , focusedBorderColor = "#cd8b00" 
     , manageHook = manageDocks <+> myManageHook <+>  manageHook defaultConfig
     , layoutHook = smartBorders $ avoidStruts  $  layoutHook defaultConfig
     , logHook = fadeInactiveLogHook 0xdddddddd >> (dynamicLogWithPP $ xmobarPP
                        { ppOutput = hPutStrLn xmproc
                        , ppTitle = xmobarColor "green" "" . shorten 50
                        })
     } `additionalKeys`
             [ ((mod4Mask .|. shiftMask, xK_z), spawn "xscreensaver-command -lock")
         , ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
         , ((0, xK_Print), spawn "scrot")
         , ((0, 0x1008ff13), spawn "/usr/local/bin/volume.sh -i")
         , ((0, 0x1008ff11), spawn "/usr/local/bin/volume.sh -d")
         , ((0, 0x1008ff12), spawn "/usr/local/bin/volume.sh -m")
         ]

Thanks!

Last edited by codemon (2011-06-12 11:02:06)

Offline

#2 2011-06-06 13:54:22

x33a
Forum Moderator
Registered: 2009-08-15
Posts: 3,548
Website

Re: [SOLVED] Make xmonad show confirmation on mod-shift-q

Well, i don't have an exact answer for your question, but maybe you could do that using xdialog, or zenity.

Offline

#3 2011-06-06 18:56:31

koomi
Member
Registered: 2010-09-26
Posts: 17

Re: [SOLVED] Make xmonad show confirmation on mod-shift-q

Yes, zenity or similar is the way to go.
It seems the only way to control xmonad from a script is to simulate a keypress, so you would have to map the script to mod+shift+q and the quit function to a diffrent combination. Or maybe you could do just the latter so nothing happens when you hit the wrong key?
I'm not familiar with haskell either, but I'm sure there is a way to get the output or exit status of a command you spawn, that way you don't have to fiddle with simulating keypress events.

To spawn a script with mod+shift+q you have to put something like this in your config:

, ((modMask .|. shiftMask,   xK_q), spawn "/path/to/script")

Have a look at the wiki article on xmonad and the config archive that is linked there, maybe someone already did something similar.

Offline

#4 2011-06-07 13:17:17

vogt
Member
From: Toronto, Canada
Registered: 2006-11-25
Posts: 389

Re: [SOLVED] Make xmonad show confirmation on mod-shift-q

Here's how to do it with dmenu. Add this to your config:

import XMonad.Util.Dmenu
import System.Exit
import Control.Monad

quitWithWarning :: X ()
quitWithWarning = do
    let m = "confirm quit"
    s <- dmenu [m]
    when (m == s) (io exitSuccess)

Then bind quitWithWarning to a key as you normally do. If you press enter and type nothing or the whole "confirm quit", it'll quit. Otherwise it does nothing, such as when you hit escape.

Offline

#5 2011-06-12 11:01:35

codemon
Member
From: India
Registered: 2009-12-08
Posts: 12
Website

Re: [SOLVED] Make xmonad show confirmation on mod-shift-q

Hi everyone,

Finally found some time to tinker with this today.

@vogt, I used your solution. Works perfectly! Thanks a lot!

And thanks to everyone else too for your suggestions smile

Offline

Board footer

Powered by FluxBB