mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
Add X.H.WorkspaceHistory
This commit is contained in:
parent
9b6ed4c505
commit
5d93450b5e
74
XMonad/Hooks/WorkspaceHistory.hs
Normal file
74
XMonad/Hooks/WorkspaceHistory.hs
Normal file
@ -0,0 +1,74 @@
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- |
|
||||
-- Module : XMonad.Hooks.WorkspaceHistory
|
||||
-- Copyright : (c) 2013 Dmitri Iouchtchenko
|
||||
-- License : BSD3-style (see LICENSE)
|
||||
--
|
||||
-- Maintainer : Dmitri Iouchtchenko <johnnyspoon@gmail.com>
|
||||
-- Stability : unstable
|
||||
-- Portability : unportable
|
||||
--
|
||||
-- Keeps track of workspace viewing order.
|
||||
--
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
module XMonad.Hooks.WorkspaceHistory
|
||||
( -- * Usage
|
||||
-- $usage
|
||||
|
||||
-- * Hooking
|
||||
workspaceHistoryHook
|
||||
|
||||
-- * Querying
|
||||
, workspaceHistory
|
||||
|
||||
) where
|
||||
|
||||
import XMonad
|
||||
import XMonad.StackSet (currentTag)
|
||||
import qualified XMonad.Util.ExtensibleState as XS
|
||||
|
||||
-- $usage
|
||||
-- To record the order in which you view workspaces, you can use this
|
||||
-- module with the following in your @~\/.xmonad\/xmonad.hs@:
|
||||
--
|
||||
-- > import XMonad.Hooks.WorkspaceHistory (workspaceHistoryHook)
|
||||
--
|
||||
-- Then add the hook to your 'logHook':
|
||||
--
|
||||
-- > main = xmonad $ defaultConfig
|
||||
-- > { ...
|
||||
-- > , logHook = ... >> workspaceHistoryHook >> ...
|
||||
-- > , ...
|
||||
-- > }
|
||||
--
|
||||
-- To make use of the collected data, a query function is provided.
|
||||
|
||||
data WorkspaceHistory =
|
||||
WorkspaceHistory { history :: [WorkspaceId] -- ^ Workspaces in reverse-chronological order.
|
||||
}
|
||||
deriving (Typeable, Read, Show)
|
||||
|
||||
instance ExtensionClass WorkspaceHistory where
|
||||
initialValue = WorkspaceHistory []
|
||||
extensionType = PersistentExtension
|
||||
|
||||
-- | A 'logHook' that keeps track of the order in which workspaces have
|
||||
-- been viewed.
|
||||
workspaceHistoryHook :: X ()
|
||||
workspaceHistoryHook = gets (currentTag . windowset) >>= (XS.modify . makeFirst)
|
||||
|
||||
-- | A list of workspace tags in the order they have been viewed, with the
|
||||
-- most recent first. No duplicates are present, but not all workspaces are
|
||||
-- guaranteed to appear, and there may be workspaces that no longer exist.
|
||||
workspaceHistory :: X [WorkspaceId]
|
||||
workspaceHistory = XS.gets history
|
||||
|
||||
|
||||
-- | Cons the 'WorkspaceId' onto the 'WorkspaceHistory' if it is not
|
||||
-- already there, or move it to the front if it is.
|
||||
makeFirst :: WorkspaceId -> WorkspaceHistory -> WorkspaceHistory
|
||||
makeFirst w v = let (xs, ys) = break (w ==) $ history v
|
||||
in v { history = w : (xs ++ drop 1 ys) }
|
@ -182,6 +182,7 @@ library
|
||||
XMonad.Hooks.ToggleHook
|
||||
XMonad.Hooks.UrgencyHook
|
||||
XMonad.Hooks.WorkspaceByPos
|
||||
XMonad.Hooks.WorkspaceHistory
|
||||
XMonad.Hooks.XPropManage
|
||||
XMonad.Layout.Accordion
|
||||
XMonad.Layout.AutoMaster
|
||||
|
Loading…
x
Reference in New Issue
Block a user