Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Created December 17, 2010 14:58
Show Gist options
  • Select an option

  • Save pbrisbin/745061 to your computer and use it in GitHub Desktop.

Select an option

Save pbrisbin/745061 to your computer and use it in GitHub Desktop.
source.hs
[1 of 1] Compiling ScratchPadKeys ( ScratchPadKeys.hs, interpreted )
ScratchPadKeys.hs:139:0:
Couldn't match expected type `XConfig l'
against inferred type `XConf'
When using functional dependencies to combine
MonadReader XConf X,
arising from the dependency `m -> r'
in the instance declaration at <no location info>
MonadReader (XConfig l) X,
arising from a use of `asks' at ScratchPadKeys.hs:141:17-29
When generalising the type(s) for `scratchMusic'
Failed, modules loaded: none.
-- in case anyone cares, here's how you get the user's terminal
-- from the config reader
getTerminal :: X String
getTerminal = asks config >>= \c@XConfig { terminal = t } -> return t
import XMonad
import XMonad.Actions.DynamicWorkspaces (addHiddenWorkspace)
import XMonad.ManageHook (composeAll)
import XMonad.Hooks.ManageHelpers (doRectFloat)
import Control.Arrow ((&&&))
import Control.Monad (filterM, when)
import qualified XMonad.StackSet as W
-- | A single scratchpad definition
data ScratchPad = ScratchPad
{ keybind :: String -- ^ The keybind to use in EZConfig notation, ex: \"M4-t\"
, cmd :: X () -- ^ The X action to take ex: spawn \"myapp\"
, query :: Query Bool -- ^ The query to find it once it's spawned
, hook :: ManageHook -- ^ the way to manage it when it's visible
}
-- | Produce a managehook to manage all scratchpads in the passed list
manageScratchPads :: [ScratchPad] -> ManageHook
manageScratchPads = composeAll . fmap (\c -> query c --> hook c)
-- | Produce a list of keybinds in /EZConfig/ notation for all
-- scratchpads in the passed list
scratchPadKeys :: [ScratchPad] -> [(String, X ())]
scratchPadKeys = fmap (keybind &&& spawnScratchpad)
-- | Summon, banish, or spawn a single 'ScratchPad'
spawnScratchpad :: ScratchPad -> X ()
spawnScratchpad sp = withWindowSet $ \s -> do
filterCurrent <- filterM (runQuery $ query sp) .
maybe [] W.integrate . W.stack . W.workspace $ W.current s
case filterCurrent of
(x:_) -> do
when
(null . filter ((== "NSP") . W.tag) $ W.workspaces s) $
addHiddenWorkspace "NSP"
windows $ W.shiftWin "NSP" x
[] -> do
filterAll <- filterM (runQuery $ query sp) $ W.allWindows s
case filterAll of
(x:_) -> windows $ W.shiftWin (W.currentTag s) x
[] -> cmd sp
-- | ncmpcpp center screen
scratchMusic :: ScratchPad
scratchMusic = ScratchPad
{ keybind = "M4-n"
, cmd = asks terminal >>= \t -> spawn $ t ++ " -name sp-ncmpcpp -e ncmpcpp"
, query = resource =? "sp-ncmpcpp"
, hook = centerScreen 0.65
}
-- | Floating, center screen with a given height
centerScreen :: Rational -> ManageHook
centerScreen h = doRectFloat $ W.RationalRect ((1 - h)/2) ((1 - h)/2) h h
-- note: this file's had unneeded code removed, so the below errors'
-- line numbers may be incorrect
[1 of 1] Compiling ScratchPadKeys ( ScratchPadKeys.hs, interpreted )
Ok, modules loaded: ScratchPadKeys.
ghci> :t asks terminal
asks terminal :: (MonadReader (XConfig l) m) => m String
ghci> :t asks terminal >>= spawn
asks terminal >>= spawn
:: (MonadReader (XConfig l) m, MonadIO m) => m ()
ghci> :info X
newtype X a
= XMonad.Core.X (mtl-1.1.0.2:Control.Monad.Reader.ReaderT
XConf (mtl-1.1.0.2:Control.Monad.State.Lazy.StateT XState IO) a)
-- Defined in XMonad.Core
instance Monad X -- Defined in XMonad.Core
instance Functor X -- Defined in XMonad.Core
instance MonadReader XConf X -- Defined in XMonad.Core
instance MonadState XState X -- Defined in XMonad.Core
instance MonadIO X -- Defined in XMonad.Core
ghci> info XConf
<interactive>:1:0: Not in scope: `info'
ghci> :info XConf
data XConf
= XConf {display :: Display,
config :: !XConfig Layout,
theRoot :: !Window,
normalBorder :: !Pixel,
focusedBorder :: !Pixel,
keyActions :: !Data.Map.Map (KeyMask, KeySym) (X ()),
buttonActions :: !Data.Map.Map (KeyMask, Button) (Window -> X ()),
mouseFocused :: !Bool,
mousePosition :: !Maybe (Position, Position)}
-- Defined in XMonad.Core
instance MonadReader XConf X -- Defined in XMonad.Core
ghci> :info XConfig
data XConfig l
= XConfig {normalBorderColor :: !String,
focusedBorderColor :: !String,
terminal :: !String,
layoutHook :: !l Window,
manageHook :: !ManageHook,
handleEventHook :: !Event -> X Data.Monoid.All,
workspaces :: ![String],
modMask :: !KeyMask,
keys :: !XConfig Layout
-> Data.Map.Map (ButtonMask, KeySym) (X ()),
mouseBindings :: !XConfig Layout
-> Data.Map.Map (ButtonMask, Button) (Window -> X ()),
borderWidth :: !Dimension,
logHook :: !X (),
startupHook :: !X (),
focusFollowsMouse :: !Bool}
-- Defined in XMonad.Core
ghci>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment