mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-07 15:31:54 -07:00
Merge pull request #521 from oogeek/add-format-wallpapersetter
X.H.WallpaperSetter: Add defWPNamesPng, defWPNamesJpg
This commit is contained in:
@@ -537,6 +537,14 @@
|
|||||||
- Added `KeepWordsLeft` and `KeepWordsRight` for keeping certain number of
|
- Added `KeepWordsLeft` and `KeepWordsRight` for keeping certain number of
|
||||||
words in left or right direction in layout description.
|
words in left or right direction in layout description.
|
||||||
|
|
||||||
|
* `XMonad.Hooks.WallpaperSetter`
|
||||||
|
|
||||||
|
- Added `defWPNamesPng`, which works like `defWPNames` but maps
|
||||||
|
`ws-name` to `ws-name.png` instead of `ws-name.jpg`.
|
||||||
|
|
||||||
|
- Added `defWPNamesJpg` as an alias to `defWPNames` and deprecated
|
||||||
|
the latter.
|
||||||
|
|
||||||
## 0.16
|
## 0.16
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
@@ -19,7 +19,7 @@ module XMonad.Hooks.WallpaperSetter (
|
|||||||
, Wallpaper(..)
|
, Wallpaper(..)
|
||||||
, WallpaperList(..)
|
, WallpaperList(..)
|
||||||
, defWallpaperConf
|
, defWallpaperConf
|
||||||
, defWPNames
|
, defWPNamesJpg, defWPNamesPng, defWPNames
|
||||||
-- *TODO
|
-- *TODO
|
||||||
-- $todo
|
-- $todo
|
||||||
) where
|
) where
|
||||||
@@ -34,7 +34,7 @@ import System.FilePath ((</>))
|
|||||||
import System.Random (randomRIO)
|
import System.Random (randomRIO)
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.List (intersperse, sortBy)
|
import Data.List (sortBy)
|
||||||
import Data.Char (isAlphaNum)
|
import Data.Char (isAlphaNum)
|
||||||
import Data.Ord (comparing)
|
import Data.Ord (comparing)
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ newtype WallpaperList = WallpaperList [(WorkspaceId, Wallpaper)]
|
|||||||
instance Monoid WallpaperList where
|
instance Monoid WallpaperList where
|
||||||
mempty = WallpaperList []
|
mempty = WallpaperList []
|
||||||
mappend (WallpaperList w1) (WallpaperList w2) =
|
mappend (WallpaperList w1) (WallpaperList w2) =
|
||||||
WallpaperList $ M.toList $ (M.fromList w2) `M.union` (M.fromList w1)
|
WallpaperList $ M.toList $ M.fromList w2 `M.union` M.fromList w1
|
||||||
|
|
||||||
instance Semigroup WallpaperList where
|
instance Semigroup WallpaperList where
|
||||||
(<>) = mappend
|
(<>) = mappend
|
||||||
@@ -100,9 +100,17 @@ defWallpaperConf = WallpaperConf "" $ WallpaperList []
|
|||||||
instance Default WallpaperConf where
|
instance Default WallpaperConf where
|
||||||
def = defWallpaperConf
|
def = defWallpaperConf
|
||||||
|
|
||||||
-- |returns the default association list (maps name to name.jpg, non-alphanumeric characters are omitted)
|
{-# DEPRECATED defWPNames "Use defWPNamesJpg instead" #-}
|
||||||
defWPNames :: [WorkspaceId] -> WallpaperList
|
defWPNames :: [WorkspaceId] -> WallpaperList
|
||||||
defWPNames xs = WallpaperList $ map (\x -> (x,WallpaperFix (filter isAlphaNum x++".jpg"))) xs
|
defWPNames = defWPNamesJpg
|
||||||
|
|
||||||
|
-- | Return the default association list (maps @name@ to @name.jpg@, non-alphanumeric characters are omitted)
|
||||||
|
defWPNamesJpg :: [WorkspaceId] -> WallpaperList
|
||||||
|
defWPNamesJpg xs = WallpaperList $ map (\x -> (x, WallpaperFix (filter isAlphaNum x ++ ".jpg"))) xs
|
||||||
|
|
||||||
|
-- | Like 'defWPNamesJpg', but map @name@ to @name.png@ instead.
|
||||||
|
defWPNamesPng :: [WorkspaceId] -> WallpaperList
|
||||||
|
defWPNamesPng xs = WallpaperList $ map (\x -> (x, WallpaperFix (filter isAlphaNum x ++ ".png"))) xs
|
||||||
|
|
||||||
-- | Add this to your log hook with the workspace configuration as argument.
|
-- | Add this to your log hook with the workspace configuration as argument.
|
||||||
wallpaperSetter :: WallpaperConf -> X ()
|
wallpaperSetter :: WallpaperConf -> X ()
|
||||||
@@ -158,7 +166,6 @@ getPicRes picpath = do
|
|||||||
[[(w,"")],[(h,"")]] -> Just (w,h)
|
[[(w,"")],[(h,"")]] -> Just (w,h)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
|
||||||
-- |complete unset fields to default values (wallpaper directory = ~/.wallpapers,
|
-- |complete unset fields to default values (wallpaper directory = ~/.wallpapers,
|
||||||
-- expects a file "NAME.jpg" for each workspace named NAME)
|
-- expects a file "NAME.jpg" for each workspace named NAME)
|
||||||
completeWPConf :: WallpaperConf -> X WallpaperConf
|
completeWPConf :: WallpaperConf -> X WallpaperConf
|
||||||
@@ -198,18 +205,18 @@ applyWallpaper parts = do
|
|||||||
layers <- liftIO $ mapM layerCommand parts
|
layers <- liftIO $ mapM layerCommand parts
|
||||||
let basepart ="convert -size " ++ show vx ++ "x" ++ show vy ++ " xc:black"
|
let basepart ="convert -size " ++ show vx ++ "x" ++ show vy ++ " xc:black"
|
||||||
endpart =" jpg:- | feh --no-xinerama --bg-tile --no-fehbg -"
|
endpart =" jpg:- | feh --no-xinerama --bg-tile --no-fehbg -"
|
||||||
cmd = basepart ++ (concat $ intersperse " " layers) ++ endpart
|
cmd = basepart ++ unwords layers ++ endpart
|
||||||
liftIO $ runCommand cmd
|
liftIO $ runCommand cmd
|
||||||
|
|
||||||
|
|
||||||
getVScreenDim :: S.StackSet i l a sid ScreenDetail -> (Integer, Integer)
|
getVScreenDim :: S.StackSet i l a sid ScreenDetail -> (Integer, Integer)
|
||||||
getVScreenDim = foldr maxXY (0,0) . map (screenRect . S.screenDetail) . S.screens
|
getVScreenDim = foldr (maxXY . screenRect . S.screenDetail) (0,0) . S.screens
|
||||||
where maxXY (Rectangle x y w h) (mx,my) = ( fromIntegral ((fromIntegral x)+w) `max` mx
|
where maxXY (Rectangle x y w h) (mx,my) = ( fromIntegral (fromIntegral x+w) `max` mx
|
||||||
, fromIntegral ((fromIntegral y)+h) `max` my )
|
, fromIntegral (fromIntegral y+h) `max` my )
|
||||||
|
|
||||||
needsRotation :: Rectangle -> (Int,Int) -> Bool
|
needsRotation :: Rectangle -> (Int,Int) -> Bool
|
||||||
needsRotation rect (px,py) = let wratio, pratio :: Double
|
needsRotation rect (px,py) = let wratio, pratio :: Double
|
||||||
wratio = (fromIntegral $ rect_width rect) / (fromIntegral $ rect_height rect)
|
wratio = fromIntegral (rect_width rect) / fromIntegral (rect_height rect)
|
||||||
pratio = fromIntegral px / fromIntegral py
|
pratio = fromIntegral px / fromIntegral py
|
||||||
in wratio > 1 && pratio < 1 || wratio < 1 && pratio > 1
|
in wratio > 1 && pratio < 1 || wratio < 1 && pratio > 1
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user