I am using XMonad in a Gnome environment. How do I define a shortcut to minimize all windows and show the desktop?


I would not recommend it, because it is not 'the way' that XMonad should be used, but I do know two possible solutions to achieve what you want.

The way that I would do that is not to hide everything in your workspace but rather to just swap to a different workspace that is empty and there is a really handy Action in xmonad-contrib to do exactly that called FindEmptyWorpace. Essentially you just use it like this:

((AltMask, xK_space), viewEmptyWorkspace)

Even though I recommended the other way I will answer the question you asked. There are the hide and reveal functions that were meant for exactly this purpose. I have never used them before because I don't want to hide anything on my screens but the function definition is enough to explain that they are X Monad Actions that act on single windows so if you want to minimise them all then you will have to grab the current screen off the StackSet and then grab the workspace on that screen and then mapM hide onto every window in window stack of that workspace. For example in ghci:

:m + XMonad.StackSet
$ :t stack . workspace . current
  :: StackSet i l a sid sd -> Maybe (Stack a)

So it could be done I just wouldn't be bothered when I could just goto a free window.


I realize that this is a very old post, but I recently found an elegant solution myself, and thought I would share it.

This solution is very nice in that it clears away all the windows, but also lets you return them to their previous state after you're done looking at the desktop.

It works by defining a new layout, and toggling to that layout on key press. A second key press will return you to whatever layout you were in.

import XMonad.Layout.MultiToggle
import XMonad.Layout.MultiToggle.Instances


data EmptyLayout a = EmptyLayout deriving (Show, Read)

instance LayoutClass EmptyLayout a where
    doLayout a b _ = emptyLayout a b
    description _ = "Empty Layout"

data HIDE = HIDE deriving (Read, Show, Eq, Typeable)
instance Transformer HIDE Window where
    transform _ x k = k (EmptyLayout) (\(EmptyLayout) -> x)


myLayoutHook = smartBorders
               . mkToggle (NOBORDERS ?? FULL ?? EOT)
               . gaps [(U,10), (R,10), (D,20), (L,10)]
               . spacingWithEdge default_spacing
               . mkToggle (single HIDE)                -- This line
               $ Grid ||| Full ||| tiled ||| Mirror tiled


keyBindings :: [((KeyMask, KeySym), X ())]
keyBindings = [ ... ((mMask, xK_z), sendMessage $ Toggle HIDE) ... ]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.