Skip to content

Instantly share code, notes, and snippets.

@LSLeary
LSLeary / Cached.hs
Created March 15, 2018 03:02
Optimise any focus-independent layout by caching rectangles?
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module Cached
( Cached
, cached
) where
import XMonad
import qualified XMonad.StackSet as W
import Data.Maybe (fromMaybe)
{-# LANGUAGE TypeApplications #-}
import Control.Applicative (ZipList(..))
import Data.Monoid (Ap(..))
import Data.Maybe (fromMaybe)
import Data.Foldable (traverse_)
every :: Int -> String -> Ap ZipList (Maybe String)
every m s = (Ap . ZipList) (cycle $ Just s : replicate (m - 1) Nothing)
import XMonad
import qualified XMonad.StackSet as W
import Graphics.X11.Xlib.Window (raiseWindow)
import XMonad.Hooks.EwmhDesktops (ewmh)
import Data.Monoid (All(..))
import qualified Data.Map.Strict as M
-- | Separate out propertyNotifyHook from the logHook.
propertyNotifyHook :: X () -> Event -> X All
import XMonad
import XMonad.Actions.PerWorkspaceKeys
import qualified Data.Map.Strict as M
-- | Given config dependent bindings per workspace, produce regular xmonad
-- bindings via @bindOn@. Use like e.g.
--
-- > main = xmonad $ def { keys = perWkspKeys myKeyBinds <+> keys def }
@LSLeary
LSLeary / Grab.hs
Created September 12, 2018 02:20
PR WIP: Modal keybindings for xmonad
{-# LANGUAGE LambdaCase #-}
--------------------------------------------------------------------------------
-- |
-- Module : XMonad.Util.Grab
-- Description : TODO
-- Copyright : (c) 2018 L. S. Leary -- TODO this is kinda wrong...
-- License : BSD3-style (see LICENSE)
--
import XMonad
import XMonad.Util.Types
import qualified XMonad.StackSet as W
import qualified Data.Map.Strict as M
import Control.Monad (when)
-- | Shift a @RationalRect@ to an edge of the screen.
toScreenEdge :: Direction2D -> W.RationalRect -> W.RationalRect
{-# LANGUAGE TypeOperators, PatternSynonyms, ExplicitNamespaces #-}
{-# LANGUAGE LambdaCase, BlockArguments #-}
module Select
( type (-?)(Fun, Const, Lazy, unLazy), ($?)
, Selective(..)
, select, branch, whenS, ifS, whileS, fromMaybeS
, (<||>), (<&&>), anyS, allS
, Monad(..)
) where
@LSLeary
LSLeary / Y.hs
Last active August 20, 2025 09:05
{-# LANGUAGE BlockArguments #-}
module Y where
newtype Y a = Y { ($$) :: Y a -> a }
{-# NOINLINE y #-}
y :: (a -> a) -> Y a
y f = Y \x -> f (x $$ x)
@LSLeary
LSLeary / ConditionalBindings.hs
Last active October 4, 2022 01:27
Conditional key bindings for xmonad. WIP.
{-# LANGUAGE StandaloneDeriving, DeriveFunctor, GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
--------------------------------------------------------------------------------
-- Module : XMonad.Actions.ConditionalBindings
-- Description : A framework for producing conditional key bindings.
-- Copyright : (c) 2018 L. S. Leary
-- License : BSD3-style (see LICENSE)
--
-- Maintainer : L. S. Leary
@LSLeary
LSLeary / ThenRefocusAfter.hs
Last active August 5, 2022 12:53
Modify an action to integrate it with RefocusLast.
module ThenRefocusAfter where
import XMonad
import XMonad.Hooks.RefocusLast (refocusWhen)
import XMonad.Util.NamedScratchpad
(NamedScratchpads, query, namedScratchpadAction)
import qualified XMonad.StackSet as W
thenRefocusAfter :: Query Bool -> X a -> X a
p `thenRefocusAfter` act = do