aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/Hooks/WindowChange.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-04-15 01:14:50 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-04-15 01:14:50 -0600
commit588e87efb099927fda713380e5bf64e8c7f1fdcd (patch)
tree979fe1f887b7e1c9ffd0f15fdee98279effcaef7 /src/Rahm/Desktop/Hooks/WindowChange.hs
parenta14486b47a51e772a3b230bc82390cb667f2ecd5 (diff)
downloadrde-588e87efb099927fda713380e5bf64e8c7f1fdcd.tar.gz
rde-588e87efb099927fda713380e5bf64e8c7f1fdcd.tar.bz2
rde-588e87efb099927fda713380e5bf64e8c7f1fdcd.zip
[WIP] - Window change hooks
Diffstat (limited to 'src/Rahm/Desktop/Hooks/WindowChange.hs')
-rw-r--r--src/Rahm/Desktop/Hooks/WindowChange.hs45
1 files changed, 45 insertions, 0 deletions
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 ()
+ }