text: I. -------------- next part -------------- 1 patch for repository: Tue Dec 25 21:26:35 CET 2012 pastorelli.mario at gmail.com * Add XMonad.Actions.ShowText New patches: [Add XMonad.Actions.ShowText pastorelli.mario at gmail.com**20121225202635 Ignore-this: 5f4818f7ec9ad37df58e73d4bb8b5590 ] { addfile ./XMonad/Actions/ShowText.hs hunk ./XMonad/Actions/ShowText.hs 1 +{-# LANGUAGE DeriveDataTypeable #-} +----------------------------------------------------------------------------- +-- | +-- Module : XMonad.Actions.ShowText +-- Copyright : (c) Mario Pastorelli (2012) +-- License : BSD-style (see xmonad/LICENSE) +-- +-- Maintainer : pastorelli.mario at gmail.com +-- Stability : unstable +-- Portability : unportable +-- +-- ShowText displays text for sometime on the screen +----------------------------------------------------------------------------- + +module XMonad.Actions.ShowText + ( -- * Usage + -- $usage + defaultSTConfig + , handleTimerEvent + , flashText + , ShowTextConfig(..) + ) where + +import Control.Monad (when) +import Data.Map (Map,empty,insert,lookup) +import Prelude hiding (lookup) +import XMonad +import XMonad.StackSet (current,screen) +import XMonad.Util.Font (Align(AlignCenter) + , initXMF + , releaseXMF + , textExtentsXMF + , textWidthXMF) +import XMonad.Util.Timer (startTimer) +import XMonad.Util.XUtils (createNewWindow + , deleteWindow + , fi + , showWindow + , paintAndWrite) +import qualified XMonad.Util.ExtensibleState as ES + +-- $usage +-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@: +-- +-- > import XMonad.Actions.ShowText +-- +-- Then add the event hook handler: +-- +-- > xmonad { handleEventHook = myHandleEventHooks <+> handleTimerEvent } +-- +-- You can then use flashText in your keybindings: +-- +-- > ((modMask, xK_Right), flashText defaultSTConfig 1 "->" >> nextWS) +-- + +-- ShowText contains the map with timers as keys and created windows as values +newtype ShowText = ShowText (Map Atom Window) + deriving (Read,Show,Typeable) + +instance ExtensionClass ShowText where + initialValue = ShowText empty + +-- | Utility to modify a ShowText +modShowText :: (Map Atom Window -> Map Atom Window) -> ShowText -> ShowText +modShowText f (ShowText m) = ShowText $ f m + +data ShowTextConfig = + STC { st_font :: String -- ^ Font name + , st_bg :: String -- ^ Background color + , st_fg :: String -- ^ Foreground color + } + +defaultSTConfig :: ShowTextConfig +defaultSTConfig = + STC { st_font = "-misc-fixed-*-*-*-*-20-*-*-*-*-*-*-*" + , st_bg = "black" + , st_fg = "white" + } + +-- | Handles timer events that notify when a window should be removed +handleTimerEvent :: Event -> X () +handleTimerEvent (ClientMessageEvent _ _ _ dis _ mtyp d) = do + (ShowText m) <- ES.get :: X ShowText + a <- io $ internAtom dis "XMONAD_TIMER" False + when (mtyp == a && length d >= 1) + (whenJust (lookup (fromIntegral $ d !! 0) m) deleteWindow) +handleTimerEvent _ = return () + +-- | Shows a window in the center of the screen with the given text +flashText :: ShowTextConfig -> Rational -> String -> X () +flashText c i s = do + f <- initXMF (st_font c) + d <- asks display + sc <- gets $ fi . screen . current . windowset + width <- textWidthXMF d f s + (as,ds) <- textExtentsXMF f s + let hight = as + ds + ht = displayHeight d sc + wh = displayWidth d sc + y = (fi ht - hight + 2) `div` 2 + x = (fi wh - width + 2) `div` 2 + w <- createNewWindow (Rectangle (fi x) (fi y) (fi width) (fi hight)) + Nothing "" True + showWindow w + paintAndWrite w f (fi width) (fi hight) 0 (st_bg c) "" + (st_fg c) (st_bg c) [AlignCenter] [s] + releaseXMF f + io $ sync d False + t <- startTimer i + ES.modify $ modShowText (insert (fromIntegral t) w) hunk ./xmonad-contrib.cabal 120 XMonad.Actions.KeyRemap XMonad.Actions.RotSlaves XMonad.Actions.Search + XMonad.Actions.ShowText XMonad.Actions.SimpleDate XMonad.Actions.SinkAll XMonad.Actions.SpawnOn } Context: [Removes unused function spawnWithActions and redundant imports in XMonad.Actions.Launcher c.lopez at kmels.net**20121215223714 Ignore-this: 76d7ac195e186b491968a548a13889c ] [A.Launcher markup identifiers for haddock links Adam Vogt <vogt.adam at gmail.com>**20121215165914 Ignore-this: 2fd3fa1dd4e00d573dd359a4b6a7291b ] [Address warnings from Debug modules Adam Vogt <vogt.adam at gmail.com>**20121215165525 Ignore-this: f97416ae4feffe4e5f9916d14d9e1524 The warnings were related to ghc-7.6 removing Prelude.catch (triggering warnings regarding the import hiding it), as well as defaulting of some numeric types. ] [Removes LocateMode and LocateRegexMode from XMonad.Actions.Launcher c.lopez at kmels.net**20121214211230 Ignore-this: b8ad32f23f15368a94202f9ad73995f2 ] [debug-hooks allbery.b at gmail.com**20120813223821 Ignore-this: 7f41c93fdd6643c687598d2fe07aad5d Hooks to print diagnostic information to stderr (usually .xsession-errors) to help debug complex issues involving the StackSet and received events. ] [Remove trailing whitespace. Adam Vogt <vogt.adam at gmail.com>**20121109014156 Ignore-this: 72e3afb6e6df47c51262006601765365 ] [Use Control.Exception.catch explitly to avoid warnings Adam Vogt <vogt.adam at gmail.com>**20121109013506 Ignore-this: 2cebdfe604c581f2b4a644e9aed726c7 The base that comes with ghc-7.6.1 no longer includes Prelude.catch; so these modules were changed so that there is no warning for import Prelude hiding (catch) At the same time these changes should be compatible with older GHCs, since the catch being has never been the one in the Prelude. ] [Add missing type signatures. Adam Vogt <vogt.adam at gmail.com>**20121109012752 Ignore-this: f54f5d9907ae48d58c98de7f8eb1f8a For whatever reason, some patches applied were missing these signatures. While haddock has been able to include inferred signatures for a while, including type signatures makes it easier to see if and when types have been changed. ] [Rename variables "state" to avoid warnings about shadowing Adam Vogt <vogt.adam at gmail.com>**20121109012316 Ignore-this: cd063d632412f758ca9fed6393521c8f XMonad core re-exports Control.Monad.State, which includes a function "state" if you happen to use mtl-2. Since there's a chance xmonad still works with mtl-1 avoid imports like: import XMonad hiding (state) ] [Rename variable in L.Minimize to avoid shadowing. Adam Vogt <vogt.adam at gmail.com>**20121109003410 Ignore-this: b46d3e8e0d4106cea6966116be386677 This "state" is new with a newer mtl. ] [Gut H.ICCCMFocus: issue 177 has been merged in core. Adam Vogt <vogt.adam at gmail.com>**20121108225716 Ignore-this: 937fe7f514ea6e36ee529e055e100e7f Keep the module for now: the LG3D bit might still be useful and there's no need to break configs unnecessarily. ]  is otherwise very difficult to do. Similarly to X.L.PerWorkspace, it provides onHost, onHosts, modHost, and modHosts layout modifiers. It attempts to do smart hostname comparison, such that short names will be matched with short names and FQDNs with FQDNs. This module currently requires that $HOST be set in the environment. You can use System.Posix.Env.setEnv to do so in xmonad.hs if need be. (Properly, this should be done via the network library, but I'm trying to avoid adding that dependency.) An alternative would be to shell out to get the name, but that has considerable portability hurdles. ] : dfa067cfe53383919e91f7bce00696b6ec520cdd