From 1507fe356d26d6a90650b0aecf806c1ddf287f9a Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 19 Feb 2022 04:22:52 +0000 Subject: Documentation: shuffling around the DBus xmonad example --- doc/quick-start.org | 67 ++----------------------------------------------- doc/window-managers.org | 65 +++++++++++++++++++++++++++++++++++++++++++++++ readme.org | 5 +++- 3 files changed, 71 insertions(+), 66 deletions(-) diff --git a/doc/quick-start.org b/doc/quick-start.org index d5bdb48..831f97c 100644 --- a/doc/quick-start.org +++ b/doc/quick-start.org @@ -465,68 +465,5 @@ available [[http://github.com/jaor/xmobar/raw/master/examples/xmobar.config][her argument that denotes an initial delay, in tenths of a second, before the command takes effect. -*** 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. - - #+begin_src haskell - ((0, xK_Alt_L), pure ()) - #+end_src - - 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). - - #+begin_src haskell - 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 - #+end_src + See [[window-managers.org::*Example of using][Interfacing with window managers]] for an example of how to use + the DBus interface from xmonad. diff --git a/doc/window-managers.org b/doc/window-managers.org index 3a194c8..09f7e3e 100644 --- a/doc/window-managers.org +++ b/doc/window-managers.org @@ -222,3 +222,68 @@ choice. xpm :: String -> String xpm = icon . (++ ".xpm") #+end_src +*** 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. + + #+begin_src haskell + ((0, xK_Alt_L), pure ()) + #+end_src + + 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). + + #+begin_src haskell + 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 + #+end_src diff --git a/readme.org b/readme.org index 179063e..25d2c55 100644 --- a/readme.org +++ b/readme.org @@ -156,12 +156,15 @@ * Configuration and further Links - - If you want to jump straight into configuring xmobar, head over to the + - If you want to jump straight into running xmobar, head over to the [[./doc/quick-start.org][quick start guide]]. - If you want to get a detailed overview of all available plugins and monitors, visit the [[./doc/plugins.org][plugins index]]. + - [[./doc/window-managers.org][Interfacing with window managers]] describes plugins and extensions + for interacting with xmobar from your window manager. + - If you want to know how to contribute to the xmobar project, check out [[contributing.org][contributing]]. -- cgit v1.2.3