{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Layout.Groups.Examples
-- Description :  Example layouts for "XMonad.Layout.Groups".
-- Copyright   :  Quentin Moser <moserq@gmail.com>
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  orphaned
-- Stability   :  unstable
-- Portability :  unportable
--
-- Example layouts for "XMonad.Layout.Groups".
--
-----------------------------------------------------------------------------

module XMonad.Layout.Groups.Examples ( -- * Usage
                                       -- $usage

                                       -- * Example: Row of columns
                                       -- $example1
                                       rowOfColumns
                                     , zoomColumnIn
                                     , zoomColumnOut
                                     , zoomColumnReset
                                     , toggleColumnFull
                                     , zoomWindowIn
                                     , zoomWindowOut
                                     , zoomWindowReset
                                     , toggleWindowFull

                                       -- * Example: Tiled tab groups
                                       -- $example2
                                     , tallTabs
                                     , mirrorTallTabs
                                     , fullTabs
                                     , TiledTabsConfig(..)
                                     , def
                                     , increaseNMasterGroups
                                     , decreaseNMasterGroups
                                     , shrinkMasterGroups
                                     , expandMasterGroups
                                     , nextOuterLayout


                                       -- * Useful re-exports and utils
                                     , module XMonad.Layout.Groups.Helpers
                                     , shrinkText
                                     , GroupEQ(..)
                                     , zoomRowG
                                     ) where

import XMonad

import qualified XMonad.Layout.Groups as G
import XMonad.Layout.Groups.Helpers

import XMonad.Layout.ZoomRow
import XMonad.Layout.Tabbed
import XMonad.Layout.Renamed
import XMonad.Layout.Decoration
import XMonad.Layout.Simplest


-- $usage
-- This module contains example 'G.Groups'-based layouts.
-- You can either import this module directly, or look at its source
-- for ideas of how "XMonad.Layout.Groups" may be used.
--
-- You can use the contents of this module by adding
--
-- > import XMonad.Layout.Groups.Examples
--
-- to the top of your @xmonad.hs@.
--
-- For more information on using any of the layouts, jump directly
--   to its \"Example\" section.
--
-- Whichever layout you choose to use, you will probably want to be
--   able to move focus and windows between groups in a consistent
--   manner. For this, you should take a look at the functions from
--   the "XMonad.Layout.Groups.Helpers" module, which are all
--   re-exported by this module.
--
-- For more information on how to extend your layoutHook and key bindings, see
-- <https://xmonad.org/TUTORIAL.html the tutorial> and "XMonad.Doc.Extending".


-- * Helper: ZoomRow of Group elements

-- | Compare two 'Group's by comparing the ids of their layouts.
data GroupEQ a = GroupEQ
  deriving (Int -> GroupEQ a -> ShowS
forall a. Int -> GroupEQ a -> ShowS
forall a. [GroupEQ a] -> ShowS
forall a. GroupEQ a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GroupEQ a] -> ShowS
$cshowList :: forall a. [GroupEQ a] -> ShowS
show :: GroupEQ a -> String
$cshow :: forall a. GroupEQ a -> String
showsPrec :: Int -> GroupEQ a -> ShowS
$cshowsPrec :: forall a. Int -> GroupEQ a -> ShowS
Show, ReadPrec [GroupEQ a]
ReadPrec (GroupEQ a)
ReadS [GroupEQ a]
forall a. ReadPrec [GroupEQ a]
forall a. ReadPrec (GroupEQ a)
forall a. Int -> ReadS (GroupEQ a)
forall a. ReadS [GroupEQ a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GroupEQ a]
$creadListPrec :: forall a. ReadPrec [GroupEQ a]
readPrec :: ReadPrec (GroupEQ a)
$creadPrec :: forall a. ReadPrec (GroupEQ a)
readList :: ReadS [GroupEQ a]
$creadList :: forall a. ReadS [GroupEQ a]
readsPrec :: Int -> ReadS (GroupEQ a)
$creadsPrec :: forall a. Int -> ReadS (GroupEQ a)
Read)

instance Eq a => EQF GroupEQ (G.Group l a) where
    eq :: GroupEQ (Group l a) -> Group l a -> Group l a -> Bool
eq GroupEQ (Group l a)
_ (G.G WithID l a
l1 Zipper a
_) (G.G WithID l a
l2 Zipper a
_) = forall (l :: * -> *) a. WithID l a -> WithID l a -> Bool
G.sameID WithID l a
l1 WithID l a
l2

zoomRowG :: (Eq a, Show a, Read a, Show (l a), Read (l a))
            => ZoomRow GroupEQ (G.Group l a)
zoomRowG :: forall a (l :: * -> *).
(Eq a, Show a, Read a, Show (l a), Read (l a)) =>
ZoomRow GroupEQ (Group l a)
zoomRowG = forall (f :: * -> *) a.
(EQF f a, Show (f a), Read (f a), Show a, Read a) =>
f a -> ZoomRow f a
zoomRowWith forall a. GroupEQ a
GroupEQ


-- * Example 1: Row of columns

-- $example1
-- A layout that arranges windows in a row of columns. It uses 'ZoomRow's for
-- both, allowing you to:
--
--  * Freely change the proportion of the screen width allocated to each column
--
--  * Freely change the proportion of a column's heigth allocated to each of its windows
--
--  * Set a column to occupy the whole screen space whenever it has focus
--
--  * Set a window to occupy its whole column whenever it has focus
--
-- to use this layout, add 'rowOfColumns' to your layout hook, for example:
--
-- > myLayout = rowOfColumns
--
-- To be able to change the sizes of columns and windows, you can create key bindings
-- for the relevant actions:
--
-- > ((modMask, xK_minus), zoomWindowOut)
--
-- and so on.

rowOfColumns :: Groups
  (ModifiedLayout Rename (Mirror (ZoomRow ClassEQ)))
  (ZoomRow GroupEQ)
  Window
rowOfColumns = forall (l :: * -> *) (l2 :: * -> *).
l Window -> l2 (Group l Window) -> Groups l l2 Window
G.group ModifiedLayout Rename (Mirror (ZoomRow ClassEQ)) Window
column forall a (l :: * -> *).
(Eq a, Show a, Read a, Show (l a), Read (l a)) =>
ZoomRow GroupEQ (Group l a)
zoomRowG
    where column :: ModifiedLayout Rename (Mirror (ZoomRow ClassEQ)) Window
column = forall a (l :: * -> *).
[Rename a] -> l a -> ModifiedLayout Rename l a
renamed [forall a. Int -> Rename a
CutWordsLeft Int
2, forall a. String -> Rename a
PrependWords String
"ZoomColumn"] forall a b. (a -> b) -> a -> b
$ forall (l :: * -> *) a. l a -> Mirror l a
Mirror forall a. (Eq a, Show a, Read a) => ZoomRow ClassEQ a
zoomRow

-- | Increase the width of the focused column
zoomColumnIn :: X ()
zoomColumnIn :: X ()
zoomColumnIn = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage ZoomMessage
zoomIn

-- | Decrease the width of the focused column
zoomColumnOut :: X ()
zoomColumnOut :: X ()
zoomColumnOut = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage ZoomMessage
zoomOut

-- | Reset the width of the focused column
zoomColumnReset :: X ()
zoomColumnReset :: X ()
zoomColumnReset = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage ZoomMessage
zoomReset

-- | Toggle whether the currently focused column should
-- take up all available space whenever it has focus
toggleColumnFull :: X ()
toggleColumnFull :: X ()
toggleColumnFull = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage ZoomMessage
ZoomFullToggle

-- | Increase the heigth of the focused window
zoomWindowIn :: X ()
zoomWindowIn :: X ()
zoomWindowIn = forall a. Message a => a -> X ()
sendMessage ZoomMessage
zoomIn

-- | Decrease the height of the focused window
zoomWindowOut :: X ()
zoomWindowOut :: X ()
zoomWindowOut = forall a. Message a => a -> X ()
sendMessage ZoomMessage
zoomOut

-- | Reset the height of the focused window
zoomWindowReset :: X ()
zoomWindowReset :: X ()
zoomWindowReset = forall a. Message a => a -> X ()
sendMessage ZoomMessage
zoomReset

-- | Toggle whether the currently focused window should
-- take up the whole column whenever it has focus
toggleWindowFull :: X ()
toggleWindowFull :: X ()
toggleWindowFull = forall a. Message a => a -> X ()
sendMessage ZoomMessage
ZoomFullToggle


-- * Example 2: Tabbed groups in a Tall/Full layout.

-- $example2
-- A layout which arranges windows into tabbed groups, and the groups
-- themselves according to XMonad's default algorithm
-- (@'Tall' ||| 'Mirror' 'Tall' ||| 'Full'@). As their names
-- indicate, 'tallTabs' starts as 'Tall', 'mirrorTallTabs' starts
-- as 'Mirror' 'Tall' and 'fullTabs' starts as 'Full', but in any
-- case you can freely switch between the three afterwards.
--
-- You can use any of these three layouts by including it in your layout hook.
-- You will need to provide it with a 'TiledTabsConfig' containing the size
-- parameters for 'Tall' and 'Mirror' 'Tall', and the shrinker and decoration theme
-- for the tabs. If you're happy with defaults, you can use 'def':
--
-- > myLayout = tallTabs def
--
-- To be able to increase\/decrease the number of master groups and shrink\/expand
-- the master area, you can create key bindings for the relevant actions:
--
-- > ((modMask, xK_h), shrinkMasterGroups)
--
-- and so on.

-- | Configuration data for the "tiled tab groups" layout
data TiledTabsConfig s = TTC { forall s. TiledTabsConfig s -> Int
vNMaster :: Int
                             , forall s. TiledTabsConfig s -> Rational
vRatio :: Rational
                             , forall s. TiledTabsConfig s -> Rational
vIncrement :: Rational
                             , forall s. TiledTabsConfig s -> Int
hNMaster :: Int
                             , forall s. TiledTabsConfig s -> Rational
hRatio :: Rational
                             , forall s. TiledTabsConfig s -> Rational
hIncrement :: Rational
                             , forall s. TiledTabsConfig s -> s
tabsShrinker :: s
                             , forall s. TiledTabsConfig s -> Theme
tabsTheme :: Theme }

instance s ~ DefaultShrinker => Default (TiledTabsConfig s) where
    def :: TiledTabsConfig s
def = forall s.
Int
-> Rational
-> Rational
-> Int
-> Rational
-> Rational
-> s
-> Theme
-> TiledTabsConfig s
TTC Int
1 Rational
0.5 (Rational
3forall a. Fractional a => a -> a -> a
/Rational
100) Int
1 Rational
0.5 (Rational
3forall a. Fractional a => a -> a -> a
/Rational
100) DefaultShrinker
shrinkText forall a. Default a => a
def

fullTabs :: TiledTabsConfig s
-> ModifiedLayout
     Rename
     (ModifiedLayout
        (Decoration TabbedDecoration s)
        (Groups
           (ModifiedLayout Rename Simplest)
           (Choose
              Full
              (Choose
                 (ModifiedLayout Rename Tall)
                 (ModifiedLayout Rename (Mirror Tall))))))
     Window
fullTabs TiledTabsConfig s
c = forall {a} {l :: * -> *} {s}.
(Eq a, LayoutClass l a, Shrinker s) =>
TiledTabsConfig s
-> l a
-> ModifiedLayout
     Rename (ModifiedLayout (Decoration TabbedDecoration s) l) a
_tab TiledTabsConfig s
c forall a b. (a -> b) -> a -> b
$ forall (l :: * -> *) (l2 :: * -> *).
l Window -> l2 (Group l Window) -> Groups l l2 Window
G.group forall {a}. ModifiedLayout Rename Simplest a
_tabs forall a b. (a -> b) -> a -> b
$ forall a. Full a
Full forall (l :: * -> *) a (r :: * -> *). l a -> r a -> Choose l r a
||| forall {s} {a}. TiledTabsConfig s -> ModifiedLayout Rename Tall a
_vert TiledTabsConfig s
c forall (l :: * -> *) a (r :: * -> *). l a -> r a -> Choose l r a
||| forall {s} {a}.
TiledTabsConfig s -> ModifiedLayout Rename (Mirror Tall) a
_horiz TiledTabsConfig s
c

tallTabs :: TiledTabsConfig s
-> ModifiedLayout
     Rename
     (ModifiedLayout
        (Decoration TabbedDecoration s)
        (Groups
           (ModifiedLayout Rename Simplest)
           (Choose
              (ModifiedLayout Rename Tall)
              (Choose (ModifiedLayout Rename (Mirror Tall)) Full))))
     Window
tallTabs TiledTabsConfig s
c = forall {a} {l :: * -> *} {s}.
(Eq a, LayoutClass l a, Shrinker s) =>
TiledTabsConfig s
-> l a
-> ModifiedLayout
     Rename (ModifiedLayout (Decoration TabbedDecoration s) l) a
_tab TiledTabsConfig s
c forall a b. (a -> b) -> a -> b
$ forall (l :: * -> *) (l2 :: * -> *).
l Window -> l2 (Group l Window) -> Groups l l2 Window
G.group forall {a}. ModifiedLayout Rename Simplest a
_tabs forall a b. (a -> b) -> a -> b
$ forall {s} {a}. TiledTabsConfig s -> ModifiedLayout Rename Tall a
_vert TiledTabsConfig s
c forall (l :: * -> *) a (r :: * -> *). l a -> r a -> Choose l r a
||| forall {s} {a}.
TiledTabsConfig s -> ModifiedLayout Rename (Mirror Tall) a
_horiz TiledTabsConfig s
c forall (l :: * -> *) a (r :: * -> *). l a -> r a -> Choose l r a
||| forall a. Full a
Full

mirrorTallTabs :: TiledTabsConfig s
-> ModifiedLayout
     Rename
     (ModifiedLayout
        (Decoration TabbedDecoration s)
        (Groups
           (ModifiedLayout Rename Simplest)
           (Choose
              (ModifiedLayout Rename (Mirror Tall))
              (Choose Full (ModifiedLayout Rename Tall)))))
     Window
mirrorTallTabs TiledTabsConfig s
c = forall {a} {l :: * -> *} {s}.
(Eq a, LayoutClass l a, Shrinker s) =>
TiledTabsConfig s
-> l a
-> ModifiedLayout
     Rename (ModifiedLayout (Decoration TabbedDecoration s) l) a
_tab TiledTabsConfig s
c forall a b. (a -> b) -> a -> b
$ forall (l :: * -> *) (l2 :: * -> *).
l Window -> l2 (Group l Window) -> Groups l l2 Window
G.group forall {a}. ModifiedLayout Rename Simplest a
_tabs forall a b. (a -> b) -> a -> b
$ forall {s} {a}.
TiledTabsConfig s -> ModifiedLayout Rename (Mirror Tall) a
_horiz TiledTabsConfig s
c forall (l :: * -> *) a (r :: * -> *). l a -> r a -> Choose l r a
||| forall a. Full a
Full forall (l :: * -> *) a (r :: * -> *). l a -> r a -> Choose l r a
||| forall {s} {a}. TiledTabsConfig s -> ModifiedLayout Rename Tall a
_vert TiledTabsConfig s
c

_tabs :: ModifiedLayout Rename Simplest a
_tabs = forall a (l :: * -> *).
[Rename a] -> l a -> ModifiedLayout Rename l a
renamed [forall a. String -> Rename a
Replace String
"Tabs"] forall a. Simplest a
Simplest

_tab :: TiledTabsConfig s
-> l a
-> ModifiedLayout
     Rename (ModifiedLayout (Decoration TabbedDecoration s) l) a
_tab TiledTabsConfig s
c l a
l = forall a (l :: * -> *).
[Rename a] -> l a -> ModifiedLayout Rename l a
renamed [forall a. Int -> Rename a
CutWordsLeft Int
1] forall a b. (a -> b) -> a -> b
$ forall a (l :: * -> *) s.
(Eq a, LayoutClass l a, Shrinker s) =>
s
-> Theme
-> l a
-> ModifiedLayout (Decoration TabbedDecoration s) l a
addTabs (forall s. TiledTabsConfig s -> s
tabsShrinker TiledTabsConfig s
c) (forall s. TiledTabsConfig s -> Theme
tabsTheme TiledTabsConfig s
c) l a
l

_vert :: TiledTabsConfig s -> ModifiedLayout Rename Tall a
_vert TiledTabsConfig s
c = forall a (l :: * -> *).
[Rename a] -> l a -> ModifiedLayout Rename l a
renamed [forall a. String -> Rename a
Replace String
"Vertical"] forall a b. (a -> b) -> a -> b
$ forall a. Int -> Rational -> Rational -> Tall a
Tall (forall s. TiledTabsConfig s -> Int
vNMaster TiledTabsConfig s
c) (forall s. TiledTabsConfig s -> Rational
vIncrement TiledTabsConfig s
c) (forall s. TiledTabsConfig s -> Rational
vRatio TiledTabsConfig s
c)

_horiz :: TiledTabsConfig s -> ModifiedLayout Rename (Mirror Tall) a
_horiz TiledTabsConfig s
c = forall a (l :: * -> *).
[Rename a] -> l a -> ModifiedLayout Rename l a
renamed [forall a. String -> Rename a
Replace String
"Horizontal"] forall a b. (a -> b) -> a -> b
$ forall (l :: * -> *) a. l a -> Mirror l a
Mirror forall a b. (a -> b) -> a -> b
$ forall a. Int -> Rational -> Rational -> Tall a
Tall (forall s. TiledTabsConfig s -> Int
hNMaster TiledTabsConfig s
c) (forall s. TiledTabsConfig s -> Rational
hIncrement TiledTabsConfig s
c) (forall s. TiledTabsConfig s -> Rational
hRatio TiledTabsConfig s
c)

-- | Increase the number of master groups by one
increaseNMasterGroups :: X ()
increaseNMasterGroups :: X ()
increaseNMasterGroups = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage forall a b. (a -> b) -> a -> b
$ Int -> IncMasterN
IncMasterN Int
1

-- | Decrease the number of master groups by one
decreaseNMasterGroups :: X ()
decreaseNMasterGroups :: X ()
decreaseNMasterGroups = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage forall a b. (a -> b) -> a -> b
$ Int -> IncMasterN
IncMasterN (-Int
1)

-- | Shrink the master area
shrinkMasterGroups :: X ()
shrinkMasterGroups :: X ()
shrinkMasterGroups = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage Resize
Shrink

-- | Expand the master area
expandMasterGroups :: X ()
expandMasterGroups :: X ()
expandMasterGroups = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage Resize
Expand

-- | Rotate the available outer layout algorithms
nextOuterLayout :: X ()
nextOuterLayout :: X ()
nextOuterLayout = forall a. Message a => a -> X ()
sendMessage forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
G.ToEnclosing forall a b. (a -> b) -> a -> b
$ forall a. Message a => a -> SomeMessage
SomeMessage ChangeLayout
NextLayout