From cc77b5a7bc8309f694fd0aed4110b92f16316c0b Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Wed, 8 Aug 2012 20:30:40 +0200 Subject: Add functions for {reveal,hid,toggl}ing the window Toggling is based is based on the current window status. If unmapped then reveal else hide. Sync is necessary or delays might occur. The functions are called from the event loop when the according signal is received When mapping (revealing) the window again we need to set the struts property again. The easiest way to do this is to call repositionWin. However, repositionWin needs access to the Config structure which is available in eventLoop. Because decomposition wouldn't be easy and I don't want to pass Config down to showWindow (which would need to return the new Rectangle then) this is done here. --- src/Window.hs | 15 +++++++++++++++ src/Xmobar.hs | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Window.hs b/src/Window.hs index 4917f57..e59c5ff 100644 --- a/src/Window.hs +++ b/src/Window.hs @@ -134,3 +134,18 @@ drawBorder b d p gc c wi ht = case b of sf >> drawRectangle d p gc mp mp (w - pad) (h - pad) where sf = setForeground d gc c (w, h) = (wi - 1, ht - 1) + +hideWindow :: Display -> Window -> IO () +hideWindow d w = do + a <- internAtom d "_NET_WM_STRUT_PARTIAL" False + c <- internAtom d "CARDINAL" False + changeProperty32 d w a c propModeReplace $ replicate 12 0 + unmapWindow d w + sync d False + +showWindow :: Display -> Window -> IO () +showWindow d w = mapWindow d w >> sync d False + +isMapped :: Display -> Window -> IO Bool +isMapped d w = fmap ism $ getWindowAttributes d w + where ism (WindowAttributes { wa_map_state = wms }) = wms /= waIsUnmapped diff --git a/src/Xmobar.hs b/src/Xmobar.hs index 1b58352..a65a236 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -140,7 +140,18 @@ eventLoop tv xc@(XConf d _ w fs cfg) signal = do ncfg <- updateConfigPosition cfg reposWindow ncfg + Hide -> hide + Reveal -> reveal + Toggle -> toggle + where + hide = hideWindow d w >> eventLoop tv xc signal + reveal = do + r' <- repositionWin d w fs cfg + showWindow d w + eventLoop tv (XConf d r' w fs cfg) signal + toggle = isMapped d w >>= \b -> if b then hide else reveal + reposWindow rcfg = do r' <- repositionWin d w fs rcfg eventLoop tv (XConf d r' w fs rcfg) signal -- cgit v1.2.3