diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2022-04-15 01:14:50 -0600 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2022-10-09 12:19:46 -0600 |
| commit | 73fe77966c249283655495e144de3c36c25e533d (patch) | |
| tree | 20cd0ce34fa899592882f2ec2f9d307489291981 /src/Rahm/Desktop | |
| parent | f92a9690f3881db347e9bd9672f83039a420e45c (diff) | |
| download | rde-73fe77966c249283655495e144de3c36c25e533d.tar.gz rde-73fe77966c249283655495e144de3c36c25e533d.tar.bz2 rde-73fe77966c249283655495e144de3c36c25e533d.zip | |
[WIP] - Window change hooks
Diffstat (limited to 'src/Rahm/Desktop')
| -rw-r--r-- | src/Rahm/Desktop/History.hs | 25 | ||||
| -rw-r--r-- | src/Rahm/Desktop/Hooks/WindowChange.hs | 45 |
2 files changed, 70 insertions, 0 deletions
diff --git a/src/Rahm/Desktop/History.hs b/src/Rahm/Desktop/History.hs new file mode 100644 index 0000000..8aff845 --- /dev/null +++ b/src/Rahm/Desktop/History.hs @@ -0,0 +1,25 @@ +module Rahm.Desktop.History where + +import Data.IntMap (IntMap) +import qualified Data.IntMap as IntMap +import Data.Default + +import Rahm.Desktop.Hooks.WindowChange + +data History = History { + currentIndex :: Int + , history :: IntMap Location + } + +instance Default History where + def = History 0 IntMap.empty + +addToHistory :: Location -> History -> History +addToHistory loc (History currentIndex hist) = + let hist' = if currentIndex > 100 + then IntMap.delete (currentIndex - 100) hist + else hist + in History (currentIndex + 1 ) (IntMap.insert currentIndex loc hist) + +historyHook :: Location -> Location -> X () +historyHook = undefined diff --git a/src/Rahm/Desktop/Hooks/WindowChange.hs b/src/Rahm/Desktop/Hooks/WindowChange.hs new file mode 100644 index 0000000..0038f47 --- /dev/null +++ b/src/Rahm/Desktop/Hooks/WindowChange.hs @@ -0,0 +1,45 @@ +module Rahm.Desktop.Hooks.WindowChange where + +import XMonad +import Control.Monad +import qualified XMonad.Util.ExtensibleState as XS +import Data.Default +import Rahm.Desktop.Workspaces + +import qualified XMonad.StackSet as W + +data Location = Location WorkspaceId (Maybe Window) + deriving (Read, Show, Eq) + +newtype LastLocation = LastLocation (Maybe Location) + deriving (Read, Show) + +instance Default LastLocation where + def = LastLocation Nothing + +instance ExtensionClass LastLocation where + initialValue = def + extensionType = PersistentExtension + +-- Creates a log hook from the function provided. +-- +-- The first argument to the function is the old window, the second argument in +-- the new window. +withLocationChangeHook :: (Location -> Location -> X ()) -> XConfig l -> XConfig l +withLocationChangeHook fn config = + config { + logHook = do + logHook config + + currentLocation <- + Location <$> getCurrentWorkspace <*> withWindowSet (return . W.peek) + + LastLocation last <- XS.get + + whenJust last $ \lastLocation -> + when (lastLocation /= currentLocation) $ + fn lastLocation currentLocation + + XS.put $ LastLocation $ Just currentLocation + return () + } |