aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsmael Carnales <icarnales@gmail.com>2009-02-05 02:30:31 +0100
committerIsmael Carnales <icarnales@gmail.com>2009-02-05 02:30:31 +0100
commit6dde16269006a318e1a1ef5a5ff6d089854db6d2 (patch)
treedceb4fbb8a2ef997116afe3b58a89749b59f76ea
parent2dac4c38e43815dbfa59fb4e810f3379a5ee8842 (diff)
downloadXMonadContrib-6dde16269006a318e1a1ef5a5ff6d089854db6d2.tar.gz
XMonadContrib-6dde16269006a318e1a1ef5a5ff6d089854db6d2.tar.xz
XMonadContrib-6dde16269006a318e1a1ef5a5ff6d089854db6d2.zip
X.U.WindowProperties: Add getProp32 and getProp32s, helpers to get properties from windows
Ignore-this: c5481fd5d97b15ca049e2da2605f65c1 darcs-hash:20090205013031-6553f-d106b609838d4ccf3fe4afa448910b897cd5b87c.gz
-rw-r--r--XMonad/Hooks/ManageDocks.hs14
-rw-r--r--XMonad/Hooks/ManageHelpers.hs13
-rw-r--r--XMonad/Util/WindowProperties.hs10
3 files changed, 18 insertions, 19 deletions
diff --git a/XMonad/Hooks/ManageDocks.hs b/XMonad/Hooks/ManageDocks.hs
index 6ca6141..88c3f0d 100644
--- a/XMonad/Hooks/ManageDocks.hs
+++ b/XMonad/Hooks/ManageDocks.hs
@@ -27,6 +27,7 @@ import XMonad
import Foreign.C.Types (CLong)
import Control.Monad
import XMonad.Layout.LayoutModifier
+import XMonad.Util.WindowProperties (getProp32s)
import Data.List (delete)
@@ -100,10 +101,9 @@ manageDocks = checkDock --> doIgnore
-- | Checks if a window is a DOCK or DESKTOP window
checkDock :: Query Bool
checkDock = ask >>= \w -> liftX $ do
- a <- getAtom "_NET_WM_WINDOW_TYPE"
dock <- getAtom "_NET_WM_WINDOW_TYPE_DOCK"
desk <- getAtom "_NET_WM_WINDOW_TYPE_DESKTOP"
- mbr <- getProp a w
+ mbr <- getProp32s "_NET_WM_WINDOW_TYPE" w
case mbr of
Just [r] -> return $ elem (fromIntegral r) [dock, desk]
_ -> return False
@@ -111,12 +111,10 @@ checkDock = ask >>= \w -> liftX $ do
-- | Gets the STRUT config, if present, in xmonad gap order
getStrut :: Window -> X [Strut]
getStrut w = do
- spa <- getAtom "_NET_WM_STRUT_PARTIAL"
- sa <- getAtom "_NET_WM_STRUT"
- msp <- getProp spa w
+ msp <- getProp32s "_NET_WM_STRUT_PARTIAL" w
case msp of
Just sp -> return $ parseStrutPartial sp
- Nothing -> fmap (maybe [] parseStrut) $ getProp sa w
+ Nothing -> fmap (maybe [] parseStrut) $ getProp32s "_NET_WM_STRUT" w
where
parseStrut xs@[_, _, _, _] = parseStrutPartial . take 12 $ xs ++ cycle [minBound, maxBound]
parseStrut _ = []
@@ -126,10 +124,6 @@ getStrut w = do
[(L, l, ly1, ly2), (R, r, ry1, ry2), (U, t, tx1, tx2), (D, b, bx1, bx2)]
parseStrutPartial _ = []
--- | Helper to read a property
-getProp :: Atom -> Window -> X (Maybe [CLong])
-getProp a w = withDisplay $ \dpy -> io $ getWindowProperty32 dpy a w
-
-- | Goes through the list of windows and find the gap so that all
-- STRUT settings are satisfied.
calcGap :: [Direction] -> X (Rectangle -> Rectangle)
diff --git a/XMonad/Hooks/ManageHelpers.hs b/XMonad/Hooks/ManageHelpers.hs
index e9a6cf3..4d6dc98 100644
--- a/XMonad/Hooks/ManageHelpers.hs
+++ b/XMonad/Hooks/ManageHelpers.hs
@@ -46,6 +46,7 @@ module XMonad.Hooks.ManageHelpers (
import XMonad
import qualified XMonad.StackSet as W
+import XMonad.Util.WindowProperties (getProp32s)
import Data.Maybe
import Data.Monoid
@@ -117,9 +118,7 @@ p -?>> f = do
-- | A predicate to check whether a window is a KDE system tray icon.
isKDETrayWindow :: Query Bool
isKDETrayWindow = ask >>= \w -> liftX $ do
- dpy <- asks display
- kde_tray <- getAtom "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR"
- r <- io $ getWindowProperty32 dpy kde_tray w
+ r <- getProp32s "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR" w
return $ case r of
Just [_] -> True
_ -> False
@@ -127,10 +126,8 @@ isKDETrayWindow = ask >>= \w -> liftX $ do
-- | Helper to check if a window property contains certain value.
isInProperty :: String -> String -> Query Bool
isInProperty p v = ask >>= \w -> liftX $ do
- dpy <- asks display
- pa <- getAtom p
va <- getAtom v
- r <- io $ getWindowProperty32 dpy pa w
+ r <- getProp32s p w
return $ case r of
Just xs -> fromIntegral va `elem` xs
_ -> False
@@ -146,9 +143,7 @@ isDialog = isInProperty "_NET_WM_WINDOW_TYPE" "_NET_WM_WINDOW_TYPE_DIALOG"
pid :: Query (Maybe ProcessID)
pid = ask >>= \w -> liftX $ do
- dpy <- asks display
- a <- getAtom "_NET_WM_PID"
- p <- io $ getWindowProperty32 dpy a w
+ p <- getProp32s "_NET_WM_PID" w
return $ case p of
Just [x] -> Just (fromIntegral x)
_ -> Nothing
diff --git a/XMonad/Util/WindowProperties.hs b/XMonad/Util/WindowProperties.hs
index d6282b1..c09efd1 100644
--- a/XMonad/Util/WindowProperties.hs
+++ b/XMonad/Util/WindowProperties.hs
@@ -15,10 +15,12 @@ module XMonad.Util.WindowProperties (
-- * Usage
-- $usage
Property(..), hasProperty, focusedHasProperty, allWithProperty,
+ getProp32, getProp32s,
propertyToQuery)
where
import XMonad
import qualified XMonad.StackSet as W
+import Foreign.C.Types (CLong)
import Control.Monad
-- $usage
@@ -78,3 +80,11 @@ propertyToQuery (And p1 p2) = propertyToQuery p1 <&&> propertyToQuery p2
propertyToQuery (Or p1 p2) = propertyToQuery p1 <||> propertyToQuery p2
propertyToQuery (Not p) = not `fmap` propertyToQuery p
propertyToQuery (Const b) = return b
+
+-- | Get a window property from atom
+getProp32 :: Atom -> Window -> X (Maybe [CLong])
+getProp32 a w = withDisplay $ \dpy -> io $ getWindowProperty32 dpy a w
+
+-- | Get a window property from string
+getProp32s :: String -> Window -> X (Maybe [CLong])
+getProp32s str w = do { a <- getAtom str; getProp32 a w }