Initial commit.
This commit is contained in:
parent
5673aceea5
commit
5d703ac967
100
Recording.hs
Normal file
100
Recording.hs
Normal file
@ -0,0 +1,100 @@
|
||||
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- |
|
||||
-- Module : LH.Recording
|
||||
-- Copyright : (c) Achim D. Brucker
|
||||
-- License : BSD3-style (see LICENSE)
|
||||
--
|
||||
-- Maintainer : Achim D. Brucker
|
||||
-- Stability : unstable
|
||||
-- Portability : unportable
|
||||
--
|
||||
-- A layout providing one window with a pre-defined size based on standard
|
||||
-- screen resolutions. This is handy for screen recording, hence the name.
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
module LH.Recording ( AspectRatio(..), Recording(..))
|
||||
where
|
||||
|
||||
import XMonad
|
||||
import qualified XMonad.StackSet as W
|
||||
|
||||
import Data.Ratio
|
||||
|
||||
import Control.Monad
|
||||
|
||||
|
||||
data AspectRatio = R4x3 | R16x10 | R16x9
|
||||
deriving(Show,Read)
|
||||
|
||||
resolution :: AspectRatio -> [(Int, Int)]
|
||||
resolution R4x3 = [(640, 480), (800, 600), (960, 720), (1024, 768), (1280, 960), (1400, 1050), (1440, 1080 ), (1600, 1200), (1856, 1392), (1920, 1440), (2048, 1536)]
|
||||
resolution R16x10 = [(1280, 800), (1440, 900), (1680, 1050), (1920, 1200), (2560, 1600)]
|
||||
resolution R16x9 = [(640, 360), (768, 432), (896, 504), (1024, 576), (1152, 648), (1280, 720), (1366, 768), (1600, 900), (1920, 1080), (2560, 1440), (3840, 2160)]
|
||||
|
||||
|
||||
data Recording a = Recording { nMaster :: !Int, aspectRatio :: AspectRatio, res :: !Int}
|
||||
deriving (Show,Read)
|
||||
|
||||
|
||||
getMaxRes aspectRatio (Rectangle _ _ x y) = length (filter (\res -> fst res < (fromIntegral x) && snd res < (fromIntegral y)) (resolution aspectRatio)) -1
|
||||
|
||||
|
||||
instance LayoutClass Recording a where
|
||||
|
||||
doLayout (Recording {nMaster = nm, aspectRatio = ar, res = rs}) r stack =
|
||||
return (doL nm x y r stack, Just $ (Recording {nMaster =nm, aspectRatio = ar, res = res'}))
|
||||
where
|
||||
res' = max 0 (min rs (getMaxRes ar r))
|
||||
(x,y) = (resolution ar)!!res'
|
||||
|
||||
handleMessage l m =
|
||||
return $ msum [fmap resize (fromMessage m)
|
||||
,fmap incmastern (fromMessage m)]
|
||||
where resize Shrink = l {res = (res l) -1}
|
||||
resize Expand = l {res = (res l) +1}
|
||||
incmastern (IncMasterN x) = l { nMaster = max 0 (n+x) }
|
||||
n = nMaster l
|
||||
description (Recording n aspectRatio res) = "Recording [ "++(show x)++"x"++(show y)++ " ]"
|
||||
where (x,y) = (resolution aspectRatio)!!res
|
||||
|
||||
|
||||
doL :: Int -> Int -> Int -> Rectangle-> W.Stack a-> [(a, Rectangle)]
|
||||
doL n x y r = ap zip (tile3 x y r n . length) . W.integrate
|
||||
|
||||
-- | tile3. Compute window positions using 3 panes
|
||||
tile3 :: Int -> Int -> Rectangle -> Int -> Int -> [Rectangle]
|
||||
tile3 xres yres r nmaster n = tile3' xres yres r (min nmaster n) nfull
|
||||
where nfull = if 0 <= (n-(max 1 nmaster)-2)
|
||||
then n
|
||||
else n - (n-(max 1 nmaster)-2)
|
||||
|
||||
tile3' :: Int -> Int -> Rectangle -> Int -> Int -> [Rectangle]
|
||||
tile3' xres yres r nmaster n
|
||||
-- | n <= nmaster || nmaster == 0 = splitVertically n r
|
||||
-- | n <= nmaster+1 = splitVertically nmaster s1 ++ splitVertically (n-nmaster) s2
|
||||
| otherwise = splitMain xres yres fheight nmaster' r1 ++ splitVertically nslave1 r2 ++ splitVertically nslave2 r3
|
||||
where (r1, r2, r3) = split3HorizontallyBy xres yres r
|
||||
(s1, s2) = splitHorizontallyBy 0.2 r -- fix
|
||||
nmaster' = max 1 nmaster
|
||||
fheight = (nmaster == 0)
|
||||
nslave = (n - nmaster')
|
||||
nslave1 = ceiling (nslave % 2)
|
||||
nslave2 = (n - nmaster' - nslave1)
|
||||
|
||||
split3HorizontallyBy :: Int -> Int -> Rectangle -> (Rectangle, Rectangle, Rectangle)
|
||||
split3HorizontallyBy xres yres (Rectangle sx sy sw sh) =
|
||||
( Rectangle (sx + (fromIntegral secondaryWidth)) sy (fromIntegral primaryWidth) sh
|
||||
, Rectangle sx sy (fromIntegral secondaryWidth) sh
|
||||
, Rectangle (sx + (fromIntegral primaryWidth) + (fromIntegral secondaryWidth)) sy (fromIntegral secondaryWidth) sh )
|
||||
where primaryWidth = xres+2
|
||||
secondaryWidth = ceiling ((sw - fromIntegral primaryWidth) % 2)
|
||||
|
||||
|
||||
|
||||
splitMain :: Int -> Int -> Bool -> Int -> Rectangle -> [Rectangle]
|
||||
splitMain _ _ True n r | n < 2 = [r]
|
||||
splitMain xres yres False n (Rectangle sx sy sw sh) | n < 2 = [Rectangle sx sy sw (fromIntegral (yres+2))]
|
||||
splitMain xres yres _ n (Rectangle sx sy sw sh) = Rectangle sx sy sw (fromIntegral (yres+2)) :
|
||||
splitVertically (n-1) (Rectangle sx (sy+fromIntegral (yres+2)) sw (sh- (fromIntegral (yres+2))))
|
||||
Loading…
Reference in New Issue
Block a user