summaryrefslogtreecommitdiffhomepage
path: root/readme.md
diff options
context:
space:
mode:
authorJochen Keil <jochen.keil@gmail.com>2012-08-22 21:27:57 +0200
committerJochen Keil <jochen.keil@gmail.com>2012-08-22 21:27:57 +0200
commita05c57f7aed141a8d6dc9038be177712be432b9d (patch)
tree1d456df5ae4a49d63460102da13c2ec54421d8bd /readme.md
parentfefeae79de28446d46dc21e193aa34fcd4fe9002 (diff)
downloadxmobar-a05c57f7aed141a8d6dc9038be177712be432b9d.tar.gz
xmobar-a05c57f7aed141a8d6dc9038be177712be432b9d.tar.bz2
Configuration example for XMonad using the DBus interface
Mainly code from my config which does the following: When I press my modifier key (which is xK_Alt_L) then xmobar appears. When I keep the key pressed for longer than 400ms (which is often the when tabbing through windows, changing workspaces, etc), then upon release xmobar will be hidden immediately. If I press xK_Alt_L for less than 400ms (very briefly), then xmobar pops up, and will automatically disappear after 2 seconds.
Diffstat (limited to 'readme.md')
-rw-r--r--readme.md61
1 files changed, 61 insertions, 0 deletions
diff --git a/readme.md b/readme.md
index f727c07..c69466e 100644
--- a/readme.md
+++ b/readme.md
@@ -345,6 +345,67 @@ It is also possible to send multiple signals at once:
dbus-send [..] \
"string:ChangeScreen" "string:Reveal 0" "string:TogglePersistent"
+### Example for using the DBus IPC interface with XMonad
+
+Bind the key which should {,un}map xmobar to a dummy value. This is necessary
+for {,un}grabKey in xmonad.
+
+ ((0, xK_Alt_L ), return ())
+
+Also, install `avoidStruts` layout modifier from `XMonad.Hooks.ManageDocks`
+
+Finally, install these two event hooks (`handleEventHook` in `XConfig`)
+`myDocksEventHook` is a replacement for `docksEventHook` which reacts on unmap
+events as well (which `docksEventHook` doesn't).
+
+ import qualified XMonad.Util.ExtensibleState as XS
+
+ data DockToggleTime = DTT { lastTime :: Time } deriving (Eq, Show, Typeable)
+
+ instance ExtensionClass DockToggleTime where
+ initialValue = DTT 0
+
+ toggleDocksHook :: Int -> KeySym -> Event -> X All
+ toggleDocksHook to ks ( KeyEvent { ev_event_display = d
+ , ev_event_type = et
+ , ev_keycode = ekc
+ , ev_time = etime
+ } ) =
+ io (keysymToKeycode d ks) >>= toggleDocks >> return (All True)
+ where
+ toggleDocks kc
+ | ekc == kc && et == keyPress = do
+ safeSendSignal ["Reveal 0", "TogglePersistent"]
+ XS.put ( DTT etime )
+ | ekc == kc && et == keyRelease = do
+ gap <- XS.gets ( (-) etime . lastTime )
+ safeSendSignal [ "TogglePersistent"
+ , "Hide " ++ show (if gap < 400 then to else 0)
+ ]
+ | otherwise = return ()
+
+ safeSendSignal s = catchX (io $ sendSignal s) (return ())
+ sendSignal = withSession . callSignal
+ withSession mc = connectSession >>= \c -> callNoReply c mc >> disconnect c
+ callSignal :: [String] -> MethodCall
+ callSignal s = ( methodCall
+ ( objectPath_ "/org/Xmobar/Control" )
+ ( interfaceName_ "org.Xmobar.Control" )
+ ( memberName_ "SendSignal" )
+ ) { methodCallDestination = Just $ busName_ "org.Xmobar.Control"
+ , methodCallBody = map toVariant s
+ }
+
+ toggleDocksHook _ _ _ = return (All True)
+
+ myDocksEventHook :: Event -> X All
+ myDocksEventHook e = do
+ when (et == mapNotify || et == unmapNotify) $
+ whenX ((not `fmap` (isClient w)) <&&> runQuery checkDock w) refresh
+ return (All True)
+ where w = ev_window e
+ et = ev_event_type e
+
## The Output Template