diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2022-04-11 22:58:45 -0600 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2022-10-09 12:19:46 -0600 |
| commit | 106695b521dedb23e314d94ba9a87e7c2e142a37 (patch) | |
| tree | 760d74abbb4f59cf725673d488957ea8fa7bcbeb /src/Rahm/Desktop/Layout/Pop.hs | |
| parent | 45fcba1681f4fda4f4ed380f00a8b6fbea681a59 (diff) | |
| download | rde-106695b521dedb23e314d94ba9a87e7c2e142a37.tar.gz rde-106695b521dedb23e314d94ba9a87e7c2e142a37.tar.bz2 rde-106695b521dedb23e314d94ba9a87e7c2e142a37.zip | |
Rename Zoom to Pop and move into its own Module.
Much cleaner.
Diffstat (limited to 'src/Rahm/Desktop/Layout/Pop.hs')
| -rw-r--r-- | src/Rahm/Desktop/Layout/Pop.hs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/Rahm/Desktop/Layout/Pop.hs b/src/Rahm/Desktop/Layout/Pop.hs new file mode 100644 index 0000000..194e645 --- /dev/null +++ b/src/Rahm/Desktop/Layout/Pop.hs @@ -0,0 +1,83 @@ +{-# LANGUAGE DeriveAnyClass #-} + +-- | The Pap layout modifier allows the user to "pop" the focused window into a +-- frame in the middle of the screen, sort of like fullscreen, but only taking +-- up a percentage of the screen rather than the whole screen so other windows +-- are still visible, alebeit typically not usable. +module Rahm.Desktop.Layout.Pop (Poppable(..), PopMessage(..), poppable) where + +import XMonad +import XMonad.Layout.LayoutModifier (LayoutModifier(..), ModifiedLayout(..)) +import Data.Default (Default(..)) +import qualified XMonad.StackSet as W + +data Poppable a = Poppable { + -- True if the current window is popped out or not. + isPopped :: Bool + + -- Fraction of the screen width around the window. + , xFrac :: Float + + -- Fraction of the screen height around the window. + , yFrac :: Float + } deriving (Show, Read, Eq, Ord) + +instance Default (Poppable a) where + def = Poppable { + isPopped = False + , xFrac = 0.05 + , yFrac = 0.05 + } + +poppable :: l a -> ModifiedLayout Poppable l a +poppable = ModifiedLayout def + +-- Message to control the state of the popped layouts modifier. +data PopMessage = TogglePop | Pop | Unpop | ResizePop Float + deriving (Typeable, Show, Eq, Ord, Message) + +instance (Eq a) => LayoutModifier Poppable a where + + -- If the current layout is not popped, then just return what the underlying + -- layout returned. + redoLayout Poppable { isPopped = False } _ _ returned = + return (returned, Nothing) + + -- Can't do anything with an empty stack. + redoLayout _ _ Nothing returned = return (returned, Nothing) + + redoLayout self (Rectangle x y w h) (Just (W.focus -> focused)) returned = + return ((focused, newRect) : remaining, Nothing) + where + remaining = filter ((/=focused) . fst) returned + wp = floor $ fromIntegral w * xFrac self + hp = floor $ fromIntegral h * yFrac self + newRect = Rectangle + (x + wp) + (y + hp) + (w - fromIntegral (wp * 2)) + (h - fromIntegral (hp * 2)) + + -- Handle the Pop messages associated with this layout. + pureMess self (fromMessage -> Just mess) = + Just $ case mess of + TogglePop -> self { isPopped = not (isPopped self) } + Pop -> self { isPopped = True } + Unpop -> self { isPopped = False } + ResizePop amt -> self { + xFrac = guard (xFrac self + amt), + yFrac = guard (yFrac self + amt) + } + where + guard = min 0.45 . max 0 + + -- Handle Shrink and Expand if it is currently in the popped state. + pureMess + self@Poppable { isPopped = True } + (fromMessage -> Just mess) = + pureMess self $ SomeMessage $ + case mess of + Shrink -> ResizePop (-0.05) + Expand -> ResizePop 0.05 + + pureMess _ _ = Nothing |