mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-07-31 04:01:51 -07:00
Apply hlint hints
All hints are applied in one single commit, as a commit per hint would result in 80+ separate commits—tihs is really just too much noise. Related: https://github.com/xmonad/xmonad-contrib/issues/537
This commit is contained in:
@@ -52,7 +52,7 @@ import Data.List (elemIndex)
|
||||
-- | Wrap string with an xmobar action that uses @xdotool@ to switch to
|
||||
-- workspace @i@.
|
||||
clickableWrap :: Int -> String -> String
|
||||
clickableWrap i ws = xmobarAction ("xdotool set_desktop " ++ show i) "1" ws
|
||||
clickableWrap i = xmobarAction ("xdotool set_desktop " ++ show i) "1"
|
||||
|
||||
-- | 'XMonad.Util.WorkspaceCompare.getWsIndex' extended to handle workspaces
|
||||
-- not in the static 'workspaces' config, such as those created by
|
||||
|
@@ -17,6 +17,7 @@ module XMonad.Util.CustomKeys (
|
||||
) where
|
||||
|
||||
import XMonad
|
||||
import XMonad.Prelude ((<&>))
|
||||
import Control.Monad.Reader
|
||||
|
||||
import qualified Data.Map as M
|
||||
@@ -70,8 +71,8 @@ customize :: XConfig l
|
||||
customize conf ds is = asks (keys conf) >>= delete ds >>= insert is
|
||||
|
||||
delete :: (MonadReader r m, Ord a) => (r -> [a]) -> M.Map a b -> m (M.Map a b)
|
||||
delete dels kmap = asks dels >>= return . foldr M.delete kmap
|
||||
delete dels kmap = asks dels <&> foldr M.delete kmap
|
||||
|
||||
insert :: (MonadReader r m, Ord a) =>
|
||||
(r -> [(a, b)]) -> M.Map a b -> m (M.Map a b)
|
||||
insert ins kmap = asks ins >>= return . foldr (uncurry M.insert) kmap
|
||||
insert ins kmap = asks ins <&> foldr (uncurry M.insert) kmap
|
||||
|
@@ -38,7 +38,7 @@ debugWindow w = do
|
||||
case w' of
|
||||
Nothing ->
|
||||
return $ "(deleted window " ++ wx ++ ")"
|
||||
Just (WindowAttributes
|
||||
Just WindowAttributes
|
||||
{ wa_x = x
|
||||
, wa_y = y
|
||||
, wa_width = wid
|
||||
@@ -46,7 +46,7 @@ debugWindow w = do
|
||||
, wa_border_width = bw
|
||||
, wa_map_state = m
|
||||
, wa_override_redirect = o
|
||||
}) -> do
|
||||
} -> do
|
||||
c' <- withDisplay $ \d ->
|
||||
io (getWindowProperty8 d wM_CLASS w)
|
||||
let c = case c' of
|
||||
@@ -70,7 +70,7 @@ debugWindow w = do
|
||||
-- NB. modern stuff often does not set WM_COMMAND since it's only ICCCM required and not some
|
||||
-- horrible gnome/freedesktop session manager thing like Wayland intended. How helpful of them.
|
||||
p' <- withDisplay $ \d -> safeGetCommand d w
|
||||
let p = if null p' then "" else wrap $ intercalate " " p'
|
||||
let p = if null p' then "" else wrap $ unwords p'
|
||||
nWP <- getAtom "_NET_WM_PID"
|
||||
pid' <- withDisplay $ \d -> io $ getWindowProperty32 d nWP w
|
||||
let pid = case pid' of
|
||||
@@ -118,7 +118,7 @@ tryUTF8 :: TextProperty -> X [String]
|
||||
tryUTF8 (TextProperty s enc _ _) = do
|
||||
uTF8_STRING <- getAtom "UTF8_STRING"
|
||||
when (enc /= uTF8_STRING) $ error "String is not UTF8_STRING"
|
||||
(map decodeString . splitNul) <$> io (peekCString s)
|
||||
map decodeString . splitNul <$> io (peekCString s)
|
||||
|
||||
tryCompound :: TextProperty -> X [String]
|
||||
tryCompound t@(TextProperty _ enc _ _) = do
|
||||
@@ -140,7 +140,7 @@ catchX' job errcase = do
|
||||
c <- ask
|
||||
(a, s') <- io $ runX c st job `E.catch` \e -> case fromException e of
|
||||
Just x -> throw e `const` (x `asTypeOf` ExitSuccess)
|
||||
_ -> runX c st errcase
|
||||
_ -> runX c st errcase
|
||||
put s'
|
||||
return a
|
||||
|
||||
|
@@ -42,27 +42,27 @@ import XMonad.Util.Run
|
||||
dmenuXinerama :: [String] -> X String
|
||||
dmenuXinerama opts = do
|
||||
curscreen <-
|
||||
(fromIntegral . W.screen . W.current) <$> gets windowset :: X Int
|
||||
fromIntegral . W.screen . W.current <$> gets windowset :: X Int
|
||||
_ <-
|
||||
runProcessWithInput "dmenu" ["-xs", show (curscreen+1)] (unlines opts)
|
||||
menuArgs "dmenu" ["-xs", show (curscreen+1)] opts
|
||||
|
||||
-- | Run dmenu to select an option from a list.
|
||||
dmenu :: MonadIO m => [String] -> m String
|
||||
dmenu opts = menu "dmenu" opts
|
||||
dmenu = menu "dmenu"
|
||||
|
||||
-- | like 'dmenu' but also takes the command to run.
|
||||
menu :: MonadIO m => String -> [String] -> m String
|
||||
menu menuCmd opts = menuArgs menuCmd [] opts
|
||||
menu menuCmd = menuArgs menuCmd []
|
||||
|
||||
-- | Like 'menu' but also takes a list of command line arguments.
|
||||
menuArgs :: MonadIO m => String -> [String] -> [String] -> m String
|
||||
menuArgs menuCmd args opts = (filter (/='\n')) <$>
|
||||
menuArgs menuCmd args opts = filter (/='\n') <$>
|
||||
runProcessWithInput menuCmd args (unlines opts)
|
||||
|
||||
-- | Like 'dmenuMap' but also takes the command to run.
|
||||
menuMap :: MonadIO m => String -> M.Map String a -> m (Maybe a)
|
||||
menuMap menuCmd selectionMap = menuMapArgs menuCmd [] selectionMap
|
||||
menuMap menuCmd = menuMapArgs menuCmd []
|
||||
|
||||
-- | Like 'menuMap' but also takes a list of command line arguments.
|
||||
menuMapArgs :: MonadIO m => String -> [String] -> M.Map String a ->
|
||||
@@ -75,4 +75,4 @@ menuMapArgs menuCmd args selectionMap = do
|
||||
|
||||
-- | Run dmenu to select an entry from a map based on the key.
|
||||
dmenuMap :: MonadIO m => M.Map String a -> m (Maybe a)
|
||||
dmenuMap selectionMap = menuMap "dmenu" selectionMap
|
||||
dmenuMap = menuMap "dmenu"
|
||||
|
@@ -45,11 +45,11 @@ import qualified XMonad.Util.ExtensibleState as XS
|
||||
-- , ((modm , xK_b), spawnDynamicSP "dyn2")
|
||||
|
||||
-- | Stores dynamic scratchpads as a map of name to window
|
||||
data SPStorage = SPStorage (M.Map String Window)
|
||||
newtype SPStorage = SPStorage (M.Map String Window)
|
||||
deriving (Typeable,Read,Show)
|
||||
|
||||
instance ExtensionClass SPStorage where
|
||||
initialValue = SPStorage $ M.fromList []
|
||||
initialValue = SPStorage M.empty
|
||||
extensionType = PersistentExtension
|
||||
|
||||
-- | Makes a window a dynamic scratchpad with the given name, or stop a window
|
||||
@@ -63,16 +63,14 @@ makeDynamicSP s w = do
|
||||
Nothing -> addDynamicSP s w
|
||||
Just ow -> if w == ow
|
||||
then removeDynamicSP s
|
||||
else (showWindow ow >> addDynamicSP s w)
|
||||
else showWindow ow >> addDynamicSP s w
|
||||
|
||||
-- | Spawn the specified dynamic scratchpad
|
||||
spawnDynamicSP :: String -- ^ Scratchpad name
|
||||
-> X ()
|
||||
spawnDynamicSP s = do
|
||||
(SPStorage m) <- XS.get
|
||||
case M.lookup s m of
|
||||
Nothing -> mempty
|
||||
Just w -> spawnDynamicSP' w
|
||||
maybe mempty spawnDynamicSP' (M.lookup s m)
|
||||
|
||||
spawnDynamicSP' :: Window -> X ()
|
||||
spawnDynamicSP' w = withWindowSet $ \s -> do
|
||||
@@ -87,7 +85,7 @@ addDynamicSP s w = XS.modify $ alterSPStorage (\_ -> Just w) s
|
||||
|
||||
-- | Make a window stop being a dynamic scratchpad
|
||||
removeDynamicSP :: String -> X ()
|
||||
removeDynamicSP s = XS.modify $ alterSPStorage (\_ -> Nothing) s
|
||||
removeDynamicSP s = XS.modify $ alterSPStorage (const Nothing) s
|
||||
|
||||
-- | Moves window to the scratchpad workspace, effectively hiding it
|
||||
hideWindow :: Window -> X ()
|
||||
@@ -96,7 +94,7 @@ hideWindow = windows . W.shiftWin "NSP"
|
||||
-- | Move window to current workspace and focus it
|
||||
showWindow :: Window -> X ()
|
||||
showWindow w = windows $ \ws ->
|
||||
(W.focusWindow w) . (W.shiftWin (W.currentTag ws) w) $ ws
|
||||
W.focusWindow w . W.shiftWin (W.currentTag ws) w $ ws
|
||||
|
||||
alterSPStorage :: (Maybe Window -> Maybe Window) -> String -> SPStorage -> SPStorage
|
||||
alterSPStorage f k (SPStorage m) = SPStorage $ M.alter f k m
|
||||
|
@@ -85,7 +85,7 @@ import Text.ParserCombinators.ReadP
|
||||
-- whichever), or add your own @myModMask = mod1Mask@ line.
|
||||
additionalKeys :: XConfig a -> [((KeyMask, KeySym), X ())] -> XConfig a
|
||||
additionalKeys conf keyList =
|
||||
conf { keys = \cnf -> M.union (M.fromList keyList) (keys conf cnf) }
|
||||
conf { keys = M.union (M.fromList keyList) . keys conf }
|
||||
|
||||
-- | Like 'additionalKeys', except using short @String@ key
|
||||
-- descriptors like @\"M-m\"@ instead of @(modMask, xK_m)@, as
|
||||
@@ -124,7 +124,7 @@ removeKeysP conf keyList =
|
||||
-- | Like 'additionalKeys', but for mouse bindings.
|
||||
additionalMouseBindings :: XConfig a -> [((ButtonMask, Button), Window -> X ())] -> XConfig a
|
||||
additionalMouseBindings conf mouseBindingsList =
|
||||
conf { mouseBindings = \cnf -> M.union (M.fromList mouseBindingsList) (mouseBindings conf cnf) }
|
||||
conf { mouseBindings = M.union (M.fromList mouseBindingsList) . mouseBindings conf }
|
||||
|
||||
-- | Like 'removeKeys', but for mouse bindings.
|
||||
removeMouseBindings :: XConfig a -> [(ButtonMask, Button)] -> XConfig a
|
||||
|
@@ -170,8 +170,8 @@ resetExclusiveSp xs = withFocused $ \w -> whenX (isScratchpad xs w) $ do
|
||||
let ys = filterM (flip runQuery w . query) xs
|
||||
|
||||
unlessX (null <$> ys) $ do
|
||||
mh <- (head . map hook) <$> ys -- ys /= [], so `head` is fine
|
||||
n <- (head . map name) <$> ys -- same
|
||||
mh <- head . map hook <$> ys -- ys /= [], so `head` is fine
|
||||
n <- head . map name <$> ys -- same
|
||||
|
||||
(windows . appEndo <=< runQuery mh) w
|
||||
hideOthers xs n
|
||||
@@ -214,7 +214,7 @@ joinQueries = foldl (<||>) (liftX $ return False)
|
||||
|
||||
-- | Useful queries
|
||||
isExclusive, isMaximized :: Query Bool
|
||||
isExclusive = (notElem "_XSP_NOEXCLUSIVE" . words) <$> stringProperty "_XMONAD_TAGS"
|
||||
isExclusive = notElem "_XSP_NOEXCLUSIVE" . words <$> stringProperty "_XMONAD_TAGS"
|
||||
isMaximized = not <$> isInProperty "_NET_WM_STATE" "_NET_WM_STATE_HIDDEN"
|
||||
|
||||
-- -----------------------------------------------------------------------------------
|
||||
|
@@ -99,7 +99,7 @@ put v = modifyStateExts . M.insert (show . typeOf $ v) . Right . extensionType $
|
||||
-- | Try to retrieve a value of the requested type, return an initial value if there is no such value.
|
||||
get :: (ExtensionClass a, XLike m) => m a
|
||||
get = getState' undefined -- `trick' to avoid needing -XScopedTypeVariables
|
||||
where toValue val = maybe initialValue id $ cast val
|
||||
where toValue val = fromMaybe initialValue $ cast val
|
||||
getState' :: (ExtensionClass a, XLike m) => a -> m a
|
||||
getState' k = do
|
||||
v <- State.gets $ M.lookup (show . typeOf $ k) . extensibleState
|
||||
@@ -110,7 +110,7 @@ get = getState' undefined -- `trick' to avoid needing -XScopedTypeVariables
|
||||
let val = fromMaybe initialValue $ cast =<< safeRead str `asTypeOf` Just x
|
||||
put (val `asTypeOf` k)
|
||||
return val
|
||||
_ -> return $ initialValue
|
||||
_ -> return initialValue
|
||||
safeRead str = case reads str of
|
||||
[(x,"")] -> Just x
|
||||
_ -> Nothing
|
||||
|
@@ -143,7 +143,7 @@ textExtentsXMF :: MonadIO m => XMonadFont -> String -> m (Int32,Int32)
|
||||
textExtentsXMF (Utf8 fs) s = do
|
||||
let (_,rl) = wcTextExtents fs s
|
||||
ascent = fi $ - (rect_y rl)
|
||||
descent = fi $ rect_height rl + (fi $ rect_y rl)
|
||||
descent = fi $ rect_height rl + fi (rect_y rl)
|
||||
return (ascent, descent)
|
||||
textExtentsXMF (Core fs) s = do
|
||||
let (_,a,d,_) = textExtents fs s
|
||||
@@ -202,4 +202,4 @@ printStringXMF dpy drw fs@(Xft font) gc fc bc x y s = do
|
||||
io $ withXftDraw dpy drw visual colormap $
|
||||
\draw -> withXftColorName dpy visual colormap fc $
|
||||
\color -> xftDrawString draw color font x y s
|
||||
#endif
|
||||
#endif
|
@@ -46,7 +46,7 @@ imageDims img = (length (head img), length img)
|
||||
-- | Return the 'x' and 'y' positions inside a 'Rectangle' to start drawing
|
||||
-- the image given its 'Placement'
|
||||
iconPosition :: Rectangle -> Placement -> [[Bool]] -> (Position,Position)
|
||||
iconPosition (Rectangle _ _ _ _) (OffsetLeft x y) _ = (fi x, fi y)
|
||||
iconPosition Rectangle{} (OffsetLeft x y) _ = (fi x, fi y)
|
||||
iconPosition (Rectangle _ _ w _) (OffsetRight x y) icon =
|
||||
let (icon_w, _) = imageDims icon
|
||||
in (fi w - fi x - fi icon_w, fi y)
|
||||
@@ -72,7 +72,7 @@ movePoint x y (Point a b) = Point (a + x) (b + y)
|
||||
|
||||
-- | Displaces a list of points along a vector 'x', 'y'
|
||||
movePoints :: Position -> Position -> [Point] -> [Point]
|
||||
movePoints x y points = map (movePoint x y) points
|
||||
movePoints x y = map (movePoint x y)
|
||||
|
||||
-- | Draw an image into a X surface
|
||||
drawIcon :: (Functor m, MonadIO m) => Display -> Drawable -> GC -> String
|
||||
|
@@ -54,7 +54,7 @@ import qualified XMonad.StackSet as W (allWindows)
|
||||
-- them instead (see 'XMonad.Util.NoTaskbar').
|
||||
|
||||
-- The extension data for tracking NSP windows
|
||||
data NSPTrack = NSPTrack [Maybe Window] deriving Typeable
|
||||
newtype NSPTrack = NSPTrack [Maybe Window] deriving Typeable
|
||||
instance ExtensionClass NSPTrack where
|
||||
initialValue = NSPTrack []
|
||||
|
||||
@@ -86,10 +86,10 @@ scratchpadWindow ns = foldM sp' Nothing (zip [0..] ns)
|
||||
--
|
||||
-- > , handleEventHook = ... <+> nspTrackHook scratchpads
|
||||
nspTrackHook :: [NamedScratchpad] -> Event -> X All
|
||||
nspTrackHook _ (DestroyWindowEvent {ev_window = w}) = do
|
||||
nspTrackHook _ DestroyWindowEvent{ev_window = w} = do
|
||||
XS.modify $ \(NSPTrack ws) -> NSPTrack $ map (\sw -> if sw == Just w then Nothing else sw) ws
|
||||
return (All True)
|
||||
nspTrackHook ns (ConfigureRequestEvent {ev_window = w}) = do
|
||||
nspTrackHook ns ConfigureRequestEvent{ev_window = w} = do
|
||||
NSPTrack ws <- XS.get
|
||||
ws' <- forM (zip3 [0 :: Integer ..] ws ns) $ \(_,w',NS _ _ q _) -> do
|
||||
p <- runQuery q w
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
||||
{-# LANGUAGE ExistentialQuantification, FlexibleContexts, FlexibleInstances, StandaloneDeriving #-}
|
||||
{-# LANGUAGE ExistentialQuantification, FlexibleContexts, FlexibleInstances, StandaloneDeriving, TupleSections #-}
|
||||
--------------------------------------------------------------------
|
||||
-- |
|
||||
-- Module : XMonad.Util.NamedActions
|
||||
@@ -51,7 +51,7 @@ import XMonad
|
||||
import System.Posix.Process(executeFile)
|
||||
import Control.Arrow(Arrow((&&&), second, (***)))
|
||||
import Data.Bits(Bits((.&.), complement))
|
||||
import System.Exit(ExitCode(ExitSuccess), exitWith)
|
||||
import System.Exit(exitSuccess)
|
||||
|
||||
import qualified Data.Map as M
|
||||
import qualified XMonad.StackSet as W
|
||||
@@ -112,7 +112,7 @@ deriving instance Show XMonad.IncMasterN
|
||||
-- | 'sendMessage' but add a description that is @show message@. Note that not
|
||||
-- all messages have show instances.
|
||||
sendMessage' :: (Message a, Show a) => a -> NamedAction
|
||||
sendMessage' x = NamedAction $ (XMonad.sendMessage x,show x)
|
||||
sendMessage' x = NamedAction (XMonad.sendMessage x,show x)
|
||||
|
||||
-- | 'spawn' but the description is the string passed
|
||||
spawn' :: String -> NamedAction
|
||||
@@ -195,7 +195,7 @@ _test = unlines $ showKm $ defaultKeysDescr XMonad.def { XMonad.layoutHook = XMo
|
||||
showKm :: [((KeyMask, KeySym), NamedAction)] -> [String]
|
||||
showKm keybindings = padding $ do
|
||||
(k,e) <- keybindings
|
||||
if snd k == 0 then map ((,) "") $ showName e
|
||||
if snd k == 0 then map ("",) $ showName e
|
||||
else map ((,) (keyToString k) . smartSpace) $ showName e
|
||||
where padding = let pad n (k,e) = if null k then "\n>> "++e else take n (k++repeat ' ') ++ e
|
||||
expand xs n = map (pad n) xs
|
||||
@@ -229,7 +229,7 @@ addDescrKeys' (k,f) ks conf =
|
||||
-- | A version of the default keys from the default configuration, but with
|
||||
-- 'NamedAction' instead of @X ()@
|
||||
defaultKeysDescr :: XConfig Layout -> [((KeyMask, KeySym), NamedAction)]
|
||||
defaultKeysDescr conf@(XConfig {XMonad.modMask = modm}) =
|
||||
defaultKeysDescr conf@XConfig{XMonad.modMask = modm} =
|
||||
[ subtitle "launching and killing programs"
|
||||
, ((modm .|. shiftMask, xK_Return), addName "Launch Terminal" $ spawn $ XMonad.terminal conf) -- %! Launch terminal
|
||||
, ((modm, xK_p ), addName "Launch dmenu" $ spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"") -- %! Launch dmenu
|
||||
@@ -267,7 +267,7 @@ defaultKeysDescr conf@(XConfig {XMonad.modMask = modm}) =
|
||||
, ((modm , xK_period), sendMessage' (IncMasterN (-1))) -- %! Deincrement the number of windows in the master area
|
||||
|
||||
, subtitle "quit, or restart"
|
||||
, ((modm .|. shiftMask, xK_q ), addName "Quit" $ io (exitWith ExitSuccess)) -- %! Quit xmonad
|
||||
, ((modm .|. shiftMask, xK_q ), addName "Quit" $ io exitSuccess) -- %! Quit xmonad
|
||||
, ((modm , xK_q ), addName "Restart" $ spawn "xmonad --recompile && xmonad --restart") -- %! Restart xmonad
|
||||
]
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
{-# LANGUAGE PatternGuards #-}
|
||||
-----------------------------------------------------------------------------
|
||||
-- |
|
||||
-- Module : XMonad.Util.NamedScratchpad
|
||||
@@ -32,7 +31,7 @@ module XMonad.Util.NamedScratchpad (
|
||||
) where
|
||||
|
||||
import XMonad
|
||||
import XMonad.Prelude (filterM, listToMaybe, unless)
|
||||
import XMonad.Prelude (filterM, find, unless)
|
||||
import XMonad.Hooks.ManageHelpers (doRectFloat)
|
||||
import XMonad.Actions.DynamicWorkspaces (addHiddenWorkspace)
|
||||
import XMonad.Hooks.DynamicLog (PP, ppSort)
|
||||
@@ -119,7 +118,7 @@ type NamedScratchpads = [NamedScratchpad]
|
||||
|
||||
-- | Finds named scratchpad configuration by name
|
||||
findByName :: NamedScratchpads -> String -> Maybe NamedScratchpad
|
||||
findByName c s = listToMaybe $ filter ((s ==) . name) c
|
||||
findByName c s = find ((s ==) . name) c
|
||||
|
||||
-- | Runs application which should appear in specified scratchpad
|
||||
runApplication :: NamedScratchpad -> X ()
|
||||
|
@@ -24,7 +24,7 @@ module XMonad.Util.NamedWindows (
|
||||
) where
|
||||
|
||||
import Control.Exception as E
|
||||
import XMonad.Prelude ( fromMaybe, listToMaybe )
|
||||
import XMonad.Prelude ( fromMaybe, listToMaybe, (>=>) )
|
||||
|
||||
import qualified XMonad.StackSet as W ( peek )
|
||||
|
||||
@@ -53,7 +53,7 @@ getName w = withDisplay $ \d -> do
|
||||
|
||||
copy prop = fromMaybe "" . listToMaybe <$> wcTextPropertyToTextList d prop
|
||||
|
||||
io $ getIt `E.catch` \(SomeException _) -> ((`NW` w) . resName) <$> getClassHint d w
|
||||
io $ getIt `E.catch` \(SomeException _) -> (`NW` w) . resName <$> getClassHint d w
|
||||
|
||||
-- | Get 'NamedWindow' using 'wM_CLASS'
|
||||
getNameWMClass :: Window -> X NamedWindow
|
||||
@@ -67,11 +67,11 @@ getNameWMClass w =
|
||||
fromMaybe "" . listToMaybe <$> wcTextPropertyToTextList d prop
|
||||
io $
|
||||
getIt `E.catch` \(SomeException _) ->
|
||||
((`NW` w) . resName) <$> getClassHint d w
|
||||
(`NW` w) . resName <$> getClassHint d w
|
||||
|
||||
unName :: NamedWindow -> Window
|
||||
unName (NW _ w) = w
|
||||
|
||||
withNamedWindow :: (NamedWindow -> X ()) -> X ()
|
||||
withNamedWindow f = do ws <- gets windowset
|
||||
whenJust (W.peek ws) $ \w -> getName w >>= f
|
||||
whenJust (W.peek ws) (getName >=> f)
|
||||
|
@@ -97,6 +97,6 @@ unicodeToKeysym :: Char -> KeySym
|
||||
unicodeToKeysym c
|
||||
| (ucp >= 32) && (ucp <= 126) = fromIntegral ucp
|
||||
| (ucp >= 160) && (ucp <= 255) = fromIntegral ucp
|
||||
| (ucp >= 256) = fromIntegral $ ucp + 0x1000000
|
||||
| ucp >= 256 = fromIntegral $ ucp + 0x1000000
|
||||
| otherwise = 0 -- this is supposed to be an error, but it's not ideal
|
||||
where ucp = fromEnum c -- codepoint
|
||||
|
@@ -34,7 +34,7 @@ import qualified Data.Map as M
|
||||
-- and windows sizes as well as positions as fractions of the screen size.
|
||||
-- This way windows can be easily relocated and scaled when switching screens.
|
||||
|
||||
data PositionStore = PS (M.Map Window PosStoreRectangle)
|
||||
newtype PositionStore = PS (M.Map Window PosStoreRectangle)
|
||||
deriving (Read,Show,Typeable)
|
||||
data PosStoreRectangle = PSRectangle Double Double Double Double
|
||||
deriving (Read,Show,Typeable)
|
||||
@@ -43,7 +43,7 @@ instance ExtensionClass PositionStore where
|
||||
initialValue = PS M.empty
|
||||
extensionType = PersistentExtension
|
||||
|
||||
getPosStore :: X (PositionStore)
|
||||
getPosStore :: X PositionStore
|
||||
getPosStore = XS.get
|
||||
|
||||
modifyPosStore :: (PositionStore -> PositionStore) -> X ()
|
||||
@@ -73,6 +73,6 @@ posStoreQuery (PS posStoreMap) w (Rectangle srX srY srWh srHt) = do
|
||||
|
||||
posStoreMove :: PositionStore -> Window -> Position -> Position -> Rectangle -> Rectangle -> PositionStore
|
||||
posStoreMove posStore w x y oldSr newSr =
|
||||
case (posStoreQuery posStore w oldSr) of
|
||||
case posStoreQuery posStore w oldSr of
|
||||
Nothing -> posStore -- not in store, can't move -> do nothing
|
||||
Just (Rectangle _ _ wh ht) -> posStoreInsert posStore w (Rectangle x y wh ht) newSr
|
||||
|
@@ -135,7 +135,7 @@ runPureX (PureX m) = runState . runReaderT m
|
||||
-- | Despite appearing less general, @PureX a@ is actually isomorphic to
|
||||
-- @XLike m => m a@.
|
||||
toXLike :: XLike m => PureX a -> m a
|
||||
toXLike pa = state =<< runPureX pa <$> ask
|
||||
toXLike pa = state . runPureX pa =<< ask
|
||||
|
||||
-- | A generalisation of 'windowBracket'. Handles refreshing for an action that
|
||||
-- __performs no refresh of its own__ but can indicate that it needs one
|
||||
@@ -155,7 +155,7 @@ defile = void . windowBracket' getAny
|
||||
-- | A version of @windowBracket@ specialised to take an @X ()@ action and
|
||||
-- perform a refresh handling any changes it makes.
|
||||
handlingRefresh :: X () -> X ()
|
||||
handlingRefresh = windowBracket (\_ -> True)
|
||||
handlingRefresh = windowBracket (const True)
|
||||
|
||||
-- }}}
|
||||
|
||||
@@ -167,7 +167,7 @@ when' b ma = if b then ma else return mempty
|
||||
|
||||
-- | A @whenX@/@whenM@ that accepts a monoidal return value.
|
||||
whenM' :: (Monad m, Monoid a) => m Bool -> m a -> m a
|
||||
whenM' mb m = when' <$> mb >>= ($ m)
|
||||
whenM' mb m = ($ m) . when' =<< mb
|
||||
|
||||
-- | A 'whenJust' that accepts a monoidal return value.
|
||||
whenJust' :: (Monad m, Monoid b) => Maybe a -> (a -> m b) -> m b
|
||||
@@ -213,7 +213,7 @@ getStack = W.stack <$> curWorkspace
|
||||
|
||||
-- | Set the stack on the current workspace.
|
||||
putStack :: XLike m => Maybe (W.Stack Window) -> m ()
|
||||
putStack mst = modifyWindowSet' . modify'' $ \_ -> mst
|
||||
putStack mst = modifyWindowSet' . modify'' $ const mst
|
||||
|
||||
-- | Get the focused window if there is one.
|
||||
peek :: XLike m => m (Maybe Window)
|
||||
|
@@ -69,7 +69,7 @@ data PointRectangle a = PointRectangle
|
||||
-- indices are unable to represent zero-dimension rectangles.
|
||||
--
|
||||
-- Consider pixels as indices. Do not use this on empty rectangles.
|
||||
pixelsToIndices :: Rectangle -> (PointRectangle Integer)
|
||||
pixelsToIndices :: Rectangle -> PointRectangle Integer
|
||||
pixelsToIndices (Rectangle px py dx dy) =
|
||||
PointRectangle (fromIntegral px)
|
||||
(fromIntegral py)
|
||||
@@ -77,7 +77,7 @@ pixelsToIndices (Rectangle px py dx dy) =
|
||||
(fromIntegral py + fromIntegral dy - 1)
|
||||
|
||||
-- | Consider pixels as @[N,N+1)@ coordinates. Available for empty rectangles.
|
||||
pixelsToCoordinates :: Rectangle -> (PointRectangle Integer)
|
||||
pixelsToCoordinates :: Rectangle -> PointRectangle Integer
|
||||
pixelsToCoordinates (Rectangle px py dx dy) =
|
||||
PointRectangle (fromIntegral px)
|
||||
(fromIntegral py)
|
||||
@@ -85,7 +85,7 @@ pixelsToCoordinates (Rectangle px py dx dy) =
|
||||
(fromIntegral py + fromIntegral dy)
|
||||
|
||||
-- | Invert 'pixelsToIndices'.
|
||||
indicesToRectangle :: (PointRectangle Integer) -> Rectangle
|
||||
indicesToRectangle :: PointRectangle Integer -> Rectangle
|
||||
indicesToRectangle (PointRectangle x1 y1 x2 y2) =
|
||||
Rectangle (fromIntegral x1)
|
||||
(fromIntegral y1)
|
||||
@@ -93,7 +93,7 @@ indicesToRectangle (PointRectangle x1 y1 x2 y2) =
|
||||
(fromIntegral $ y2 - y1 + 1)
|
||||
|
||||
-- | Invert 'pixelsToCoordinates'.
|
||||
coordinatesToRectangle :: (PointRectangle Integer) -> Rectangle
|
||||
coordinatesToRectangle :: PointRectangle Integer -> Rectangle
|
||||
coordinatesToRectangle (PointRectangle x1 y1 x2 y2) =
|
||||
Rectangle (fromIntegral x1)
|
||||
(fromIntegral y1)
|
||||
@@ -105,7 +105,7 @@ coordinatesToRectangle (PointRectangle x1 y1 x2 y2) =
|
||||
empty :: Rectangle -> Bool
|
||||
empty (Rectangle _ _ _ 0) = True
|
||||
empty (Rectangle _ _ 0 _) = True
|
||||
empty (Rectangle _ _ _ _) = False
|
||||
empty Rectangle{} = False
|
||||
|
||||
-- | True if the intersection of the set of points comprising each rectangle is
|
||||
-- not the empty set. Therefore any rectangle containing the initial points of
|
||||
@@ -141,21 +141,13 @@ difference r1 r2 | r1 `intersects` r2 = map coordinatesToRectangle $
|
||||
where PointRectangle r1_x1 r1_y1 r1_x2 r1_y2 = pixelsToCoordinates r1
|
||||
PointRectangle r2_x1 r2_y1 r2_x2 r2_y2 = pixelsToCoordinates r2
|
||||
-- top - assuming (0,0) is top-left
|
||||
rt = if r2_y1 > r1_y1 && r2_y1 < r1_y2
|
||||
then [PointRectangle (max r2_x1 r1_x1) r1_y1 r1_x2 r2_y1]
|
||||
else []
|
||||
rt = [PointRectangle (max r2_x1 r1_x1) r1_y1 r1_x2 r2_y1 | r2_y1 > r1_y1 && r2_y1 < r1_y2]
|
||||
-- right
|
||||
rr = if r2_x2 > r1_x1 && r2_x2 < r1_x2
|
||||
then [PointRectangle r2_x2 (max r2_y1 r1_y1) r1_x2 r1_y2]
|
||||
else []
|
||||
rr = [PointRectangle r2_x2 (max r2_y1 r1_y1) r1_x2 r1_y2 | r2_x2 > r1_x1 && r2_x2 < r1_x2]
|
||||
-- bottom
|
||||
rb = if r2_y2 > r1_y1 && r2_y2 < r1_y2
|
||||
then [PointRectangle r1_x1 r2_y2 (min r2_x2 r1_x2) r1_y2]
|
||||
else []
|
||||
rb = [PointRectangle r1_x1 r2_y2 (min r2_x2 r1_x2) r1_y2 | r2_y2 > r1_y1 && r2_y2 < r1_y2]
|
||||
-- left
|
||||
rl = if r2_x1 > r1_x1 && r2_x1 < r1_x2
|
||||
then [PointRectangle r1_x1 r1_y1 r2_x1 (min r2_y2 r1_y2)]
|
||||
else []
|
||||
rl = [PointRectangle r1_x1 r1_y1 r2_x1 (min r2_y2 r1_y2) | r2_x1 > r1_x1 && r2_x1 < r1_x2]
|
||||
|
||||
-- | Fit a 'Rectangle' within the given borders of itself. Given insufficient
|
||||
-- space, borders are minimized while preserving the ratio of opposite borders.
|
||||
@@ -198,8 +190,8 @@ withBorder t b r l i (Rectangle x y w h) =
|
||||
-- | Calculate the center - @(x,y)@ - as if the 'Rectangle' were bounded.
|
||||
center :: Rectangle -> (Ratio Integer,Ratio Integer)
|
||||
center (Rectangle x y w h) = (cx,cy)
|
||||
where cx = fromIntegral x + (fromIntegral w) % 2
|
||||
cy = fromIntegral y + (fromIntegral h) % 2
|
||||
where cx = fromIntegral x + fromIntegral w % 2
|
||||
cy = fromIntegral y + fromIntegral h % 2
|
||||
|
||||
-- | Invert 'scaleRationalRect'. Since that operation is lossy a roundtrip
|
||||
-- conversion may not result in the original value. The first 'Rectangle' is
|
||||
|
@@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
-----------------------------------------------------------------------------
|
||||
-- |
|
||||
-- Module : XMonad.Util.RemoteWindows
|
||||
@@ -71,7 +72,7 @@ setRemoteProp w host = do
|
||||
-- checking environment variables and assuming that hostname never
|
||||
-- changes.
|
||||
isLocalWindow :: Window -> X Bool
|
||||
isLocalWindow w = getProp32s "XMONAD_REMOTE" w >>= \p -> case p of
|
||||
isLocalWindow w = getProp32s "XMONAD_REMOTE" w >>= \case
|
||||
Just [y] -> return $ y == 0
|
||||
_ -> io guessHostName >>= \host -> hasProperty (Machine host) w
|
||||
|
||||
|
@@ -1,4 +1,3 @@
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
-----------------------------------------------------------------------------
|
||||
-- |
|
||||
-- Module : XMonad.Util.Replace
|
||||
@@ -78,11 +77,11 @@ replace = do
|
||||
rootw <- rootWindow dpy dflt
|
||||
|
||||
-- check for other WM
|
||||
wmSnAtom <- internAtom dpy ("WM_S" ++ (show dflt)) False
|
||||
wmSnAtom <- internAtom dpy ("WM_S" ++ show dflt) False
|
||||
currentWmSnOwner <- xGetSelectionOwner dpy wmSnAtom
|
||||
when (currentWmSnOwner /= 0) $ do
|
||||
putStrLn $ "Screen " ++ (show dflt) ++ " on display \""
|
||||
++ (displayString dpy) ++ "\" already has a window manager."
|
||||
putStrLn $ "Screen " ++ show dflt ++ " on display \""
|
||||
++ displayString dpy ++ "\" already has a window manager."
|
||||
|
||||
-- prepare to receive destroyNotify for old WM
|
||||
selectInput dpy currentWmSnOwner structureNotifyMask
|
||||
@@ -97,19 +96,19 @@ replace = do
|
||||
createWindow dpy rootw (-100) (-100) 1 1 0 copyFromParent copyFromParent visual attrmask attributes
|
||||
|
||||
-- try to acquire wmSnAtom, this should signal the old WM to terminate
|
||||
putStrLn $ "Replacing existing window manager..."
|
||||
putStrLn "Replacing existing window manager..."
|
||||
xSetSelectionOwner dpy wmSnAtom netWmSnOwner currentTime
|
||||
|
||||
-- SKIPPED: check if we acquired the selection
|
||||
-- SKIPPED: send client message indicating that we are now the WM
|
||||
|
||||
-- wait for old WM to go away
|
||||
putStr $ "Waiting for other window manager to terminate... "
|
||||
putStr "Waiting for other window manager to terminate... "
|
||||
fix $ \again -> do
|
||||
evt <- allocaXEvent $ \event -> do
|
||||
windowEvent dpy currentWmSnOwner structureNotifyMask event
|
||||
get_EventType event
|
||||
|
||||
when (evt /= destroyNotify) again
|
||||
putStrLn $ "done"
|
||||
putStrLn "done"
|
||||
closeDisplay dpy
|
||||
|
@@ -33,12 +33,12 @@ import qualified XMonad.Util.ExtensibleState as XS
|
||||
-- Add 'setSessionStarted' at the end of the 'startupHook' to set the
|
||||
-- flag.
|
||||
--
|
||||
-- To do something only when the session is started up, use
|
||||
-- To do something only when the session is started up, use
|
||||
-- 'isSessionStart' to query or wrap it in 'doOnce' to only do it when
|
||||
-- the flag isn't set.
|
||||
-- ---------------------------------------------------------------------
|
||||
|
||||
data SessionStart = SessionStart { unSessionStart :: Bool }
|
||||
newtype SessionStart = SessionStart { unSessionStart :: Bool }
|
||||
deriving (Read, Show, Typeable)
|
||||
|
||||
instance ExtensionClass SessionStart where
|
||||
|
@@ -50,7 +50,7 @@ import qualified Data.Map as Map
|
||||
-- > , logHook = logHook'}
|
||||
--
|
||||
|
||||
data NamedPipes = NamedPipes { pipeMap :: Map.Map String Handle }
|
||||
newtype NamedPipes = NamedPipes { pipeMap :: Map.Map String Handle }
|
||||
deriving (Show, Typeable)
|
||||
|
||||
instance ExtensionClass NamedPipes where
|
||||
|
@@ -23,7 +23,7 @@ import Data.Set as Set
|
||||
import qualified XMonad.Util.ExtensibleState as XS
|
||||
import XMonad.Prelude
|
||||
|
||||
data SpawnOnce = SpawnOnce { unspawnOnce :: (Set String) }
|
||||
newtype SpawnOnce = SpawnOnce { unspawnOnce :: Set String }
|
||||
deriving (Read, Show, Typeable)
|
||||
|
||||
instance ExtensionClass SpawnOnce where
|
||||
@@ -33,7 +33,7 @@ instance ExtensionClass SpawnOnce where
|
||||
doOnce :: (String -> X ()) -> String -> X ()
|
||||
doOnce f s = do
|
||||
b <- XS.gets (Set.member s . unspawnOnce)
|
||||
when (not b) $ do
|
||||
unless b $ do
|
||||
f s
|
||||
XS.modify (SpawnOnce . Set.insert s . unspawnOnce)
|
||||
|
||||
@@ -42,19 +42,19 @@ doOnce f s = do
|
||||
-- that command is executed. Subsequent invocations for a command do
|
||||
-- nothing.
|
||||
spawnOnce :: String -> X ()
|
||||
spawnOnce cmd = doOnce spawn cmd
|
||||
spawnOnce = doOnce spawn
|
||||
|
||||
-- | Like spawnOnce but launches the application on the given workspace.
|
||||
spawnOnOnce :: WorkspaceId -> String -> X ()
|
||||
spawnOnOnce ws cmd = doOnce (spawnOn ws) cmd
|
||||
spawnOnOnce ws = doOnce (spawnOn ws)
|
||||
|
||||
-- | Lanch the given application n times on the specified
|
||||
-- workspace. Subsequent attempts to spawn this application will be
|
||||
-- ignored.
|
||||
spawnNOnOnce :: Int -> WorkspaceId -> String -> X ()
|
||||
spawnNOnOnce n ws cmd = doOnce (\c -> sequence_ $ replicate n $ spawnOn ws c) cmd
|
||||
spawnNOnOnce n ws = doOnce (replicateM_ n . spawnOn ws)
|
||||
|
||||
-- | Spawn the application once and apply the manage hook. Subsequent
|
||||
-- attempts to spawn this application will be ignored.
|
||||
spawnAndDoOnce :: ManageHook -> String -> X ()
|
||||
spawnAndDoOnce mh cmd = doOnce (spawnAndDo mh) cmd
|
||||
spawnAndDoOnce mh = doOnce (spawnAndDo mh)
|
||||
|
@@ -218,7 +218,7 @@ sortByZ f = fromTags . sortBy (adapt f) . toTags
|
||||
-- | Map a function over a stack. The boolean argument indcates whether
|
||||
-- the current element is the focused one
|
||||
mapZ :: (Bool -> a -> b) -> Zipper a -> Zipper b
|
||||
mapZ f as = fromTags . map (mapE f) . toTags $ as
|
||||
mapZ f = fromTags . map (mapE f) . toTags
|
||||
|
||||
-- | 'mapZ' without the 'Bool' argument
|
||||
mapZ_ :: (a -> b) -> Zipper a -> Zipper b
|
||||
@@ -316,7 +316,7 @@ foldlZ_ = foldlZ . const
|
||||
|
||||
-- | Find whether an element is present in a stack.
|
||||
elemZ :: Eq a => a -> Zipper a -> Bool
|
||||
elemZ a as = foldlZ_ step False as
|
||||
elemZ a = foldlZ_ step False
|
||||
where step True _ = True
|
||||
step False a' = a' == a
|
||||
|
||||
|
@@ -49,7 +49,7 @@ startTimer s = io $ do
|
||||
-- | Given a 'TimerId' and an 'Event', run an action when the 'Event'
|
||||
-- has been sent by the timer specified by the 'TimerId'
|
||||
handleTimer :: TimerId -> Event -> X (Maybe a) -> X (Maybe a)
|
||||
handleTimer ti (ClientMessageEvent {ev_message_type = mt, ev_data = dt}) action = do
|
||||
handleTimer ti ClientMessageEvent{ev_message_type = mt, ev_data = dt} action = do
|
||||
d <- asks display
|
||||
a <- io $ internAtom d "XMONAD_TIMER" False
|
||||
if mt == a && dt /= [] && fromIntegral (head dt) == ti
|
||||
|
@@ -52,7 +52,7 @@ infixr 8 `Or`
|
||||
|
||||
-- | Does given window have this property?
|
||||
hasProperty :: Property -> Window -> X Bool
|
||||
hasProperty p w = runQuery (propertyToQuery p) w
|
||||
hasProperty p = runQuery (propertyToQuery p)
|
||||
|
||||
-- | Does the focused window have this property?
|
||||
focusedHasProperty :: Property -> X Bool
|
||||
|
@@ -70,7 +70,7 @@ catchQuery q = packIntoQuery $ \win -> userCode $ runQuery q win
|
||||
-- | Instance of MonadState for StateQuery.
|
||||
instance (Show s, Read s, Typeable s) => MonadState (Maybe s) (StateQuery s) where
|
||||
get = StateQuery $ read' <$> get' undefined where
|
||||
get' :: (Maybe s) -> Query String
|
||||
get' :: Maybe s -> Query String
|
||||
get' x = stringProperty (typePropertyName x)
|
||||
read' :: (Read s) => String -> Maybe s
|
||||
read' "" = Nothing
|
||||
|
@@ -24,7 +24,6 @@ module XMonad.Util.XSelection ( -- * Usage
|
||||
|
||||
import Control.Exception as E (catch,SomeException(..))
|
||||
import XMonad
|
||||
import XMonad.Prelude (fromMaybe)
|
||||
import XMonad.Util.Run (safeSpawn, unsafeSpawn)
|
||||
|
||||
import Codec.Binary.UTF8.String (decode)
|
||||
@@ -68,7 +67,7 @@ getSelection = io $ do
|
||||
ev <- getEvent e
|
||||
result <- if ev_event_type ev == selectionNotify
|
||||
then do res <- getWindowProperty8 dpy clp win
|
||||
return $ decode . map fromIntegral . fromMaybe [] $ res
|
||||
return $ decode . maybe [] (map fromIntegral) $ res
|
||||
else destroyWindow dpy win >> return ""
|
||||
closeDisplay dpy
|
||||
return result
|
||||
|
@@ -127,8 +127,8 @@ paintAndWrite :: Window -- ^ The window where to draw
|
||||
-> X ()
|
||||
paintAndWrite w fs wh ht bw bc borc ffc fbc als strs = do
|
||||
d <- asks display
|
||||
strPositions <- forM (zip als strs) $ \(al, str) ->
|
||||
stringPosition d fs (Rectangle 0 0 wh ht) al str
|
||||
strPositions <- forM (zip als strs) $
|
||||
uncurry (stringPosition d fs (Rectangle 0 0 wh ht))
|
||||
let ms = Just (fs,ffc,fbc, zip strs strPositions)
|
||||
paintWindow' w (Rectangle 0 0 wh ht) bw bc borc ms Nothing
|
||||
|
||||
@@ -150,9 +150,8 @@ paintTextAndIcons :: Window -- ^ The window where to draw
|
||||
-> X ()
|
||||
paintTextAndIcons w fs wh ht bw bc borc ffc fbc als strs i_als icons = do
|
||||
d <- asks display
|
||||
strPositions <- forM (zip als strs) $ \(al, str) ->
|
||||
stringPosition d fs (Rectangle 0 0 wh ht) al str
|
||||
let iconPositions = map ( \(al, icon) -> iconPosition (Rectangle 0 0 wh ht) al icon ) (zip i_als icons)
|
||||
strPositions <- forM (zip als strs) $ uncurry (stringPosition d fs (Rectangle 0 0 wh ht))
|
||||
let iconPositions = zipWith (iconPosition (Rectangle 0 0 wh ht)) i_als icons
|
||||
ms = Just (fs,ffc,fbc, zip strs strPositions)
|
||||
is = Just (ffc, fbc, zip iconPositions icons)
|
||||
paintWindow' w (Rectangle 0 0 wh ht) bw bc borc ms is
|
||||
|
Reference in New Issue
Block a user