aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Util/SpawnOnWorkspace.hs
diff options
context:
space:
mode:
authorDaniel Schoepe <asgaroth_@gmx.de>2009-01-25 20:10:45 +0100
committerDaniel Schoepe <asgaroth_@gmx.de>2009-01-25 20:10:45 +0100
commitb839c6c4d91ddcba51edbe009970f8c42f11858a (patch)
treeb2292aeab5b16f3db0346cb9b30dabeaee652f73 /XMonad/Util/SpawnOnWorkspace.hs
parent1ff118f29fe018d867fb2a4793ec5b2cf928c3b1 (diff)
downloadXMonadContrib-b839c6c4d91ddcba51edbe009970f8c42f11858a.tar.gz
XMonadContrib-b839c6c4d91ddcba51edbe009970f8c42f11858a.tar.xz
XMonadContrib-b839c6c4d91ddcba51edbe009970f8c42f11858a.zip
Support for spawning most applications on a specific workspace
Ignore-this: 26076d54b131e037b42c87e4fde63200 darcs-hash:20090125191045-cb1c6-124cbecad2e7fa37ada2c6c938a95e3e4ad4e037.gz
Diffstat (limited to '')
-rw-r--r--XMonad/Util/SpawnOnWorkspace.hs81
1 files changed, 81 insertions, 0 deletions
diff --git a/XMonad/Util/SpawnOnWorkspace.hs b/XMonad/Util/SpawnOnWorkspace.hs
new file mode 100644
index 0000000..f93ca24
--- /dev/null
+++ b/XMonad/Util/SpawnOnWorkspace.hs
@@ -0,0 +1,81 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonad.Util.SpawnOnWorkspace
+-- Copyright : (c) 2009 Daniel Schoepe
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : Daniel Schoepe <asgaroth_@gmx.de>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- Provides a way to spawn an application on a specific workspace by using
+-- the _NET_WM_PID property that most windows set on creation. Hence this module
+-- won't work on applications that don't set this property.
+--
+-----------------------------------------------------------------------------
+module XMonad.Util.SpawnOnWorkspace (
+ -- * Usage
+ -- $usage
+
+ -- * Documentation
+ -- $documentation
+
+ spawnOnWorkspace,
+ spawnOnWorkspaceHook,
+ mkSpawnHelper,
+ SpawnHelper
+ ) where
+import XMonad
+import XMonad.Hooks.ManageHelpers
+import Data.IORef
+import Data.Maybe
+import qualified Data.Map as M
+import System.Posix.Types
+
+-- $usage
+-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
+--
+-- > import XMonad
+-- > import XMonad.Util.SpawnOnWorkspace
+--
+-- > main = do
+-- > sh <- mkSpawnHelper
+-- > ..
+--
+-- Then you need to add 'spawnOnWorkspaceHook' to your manage hook:
+--
+-- > manageHook = spawnOnWorkspaceHook sh <+> manageHook defaultConfig
+--
+-- To spawn an application on a specific workspace, add a keybinding:
+--
+-- > ((mod1Mask,xK_o), spawnOnWorkspace sh "urxvt" "3")
+--
+-- For detailed instructions on editing your key bindings, see
+-- "XMonad.Doc.Extending#Editing_key_bindings".
+--
+
+-------------------------------------------------------------------
+
+-- $documentation
+
+-- | This structure holds the process ids and corresponding
+-- workspaces for processes created with 'spawnOnWorkspace'
+type SpawnHelper = IORef (M.Map ProcessID WorkspaceId)
+
+-- | Creates a new spawn helper.
+mkSpawnHelper :: IO SpawnHelper
+mkSpawnHelper = newIORef M.empty
+
+-- | Provides a manage hook to react on process spawned with
+-- 'spawnOnWorkspace'.
+spawnOnWorkspaceHook :: SpawnHelper -> ManageHook
+spawnOnWorkspaceHook sh = do
+ pd <- fromMaybe (-1) `fmap` pid
+ table <- io $ readIORef sh
+ case M.lookup pd table of
+ Just ws -> io (modifyIORef sh (M.delete pd)) >> doShift ws
+ Nothing -> doF id
+
+-- | Spawns a process on the specified workspace.
+spawnOnWorkspace :: SpawnHelper -> String -> WorkspaceId -> X ()
+spawnOnWorkspace sh cmd ws = spawnPID cmd >>= io . modifyIORef sh . flip M.insert ws