From 76557c53f60bab75459db03e29c50f5d6ae55309 Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 3 Feb 2022 23:52:42 +0000 Subject: Xmobar.X11.Actions -> Xmobar.Run.Actions --- src/Xmobar/App/X11EventLoop.hs | 2 +- src/Xmobar/Plugins/StdinReader.hs | 2 +- src/Xmobar/Plugins/XMonadLog.hs | 4 +++- src/Xmobar/Run/Actions.hs | 36 ++++++++++++++++++++++++++++++++++++ src/Xmobar/X11/Actions.hs | 34 ---------------------------------- src/Xmobar/X11/Bitmap.hs | 4 ++-- src/Xmobar/X11/Draw.hs | 2 +- src/Xmobar/X11/Parsers.hs | 3 +-- 8 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 src/Xmobar/Run/Actions.hs delete mode 100644 src/Xmobar/X11/Actions.hs (limited to 'src/Xmobar') diff --git a/src/Xmobar/App/X11EventLoop.hs b/src/Xmobar/App/X11EventLoop.hs index 7021b21..b8897b5 100644 --- a/src/Xmobar/App/X11EventLoop.hs +++ b/src/Xmobar/App/X11EventLoop.hs @@ -50,7 +50,7 @@ import Xmobar.Config.Types ( persistent , Align(..) , XPosition(..)) -import Xmobar.X11.Actions +import Xmobar.Run.Actions import Xmobar.X11.Parsers import Xmobar.X11.Window import Xmobar.X11.Text diff --git a/src/Xmobar/Plugins/StdinReader.hs b/src/Xmobar/Plugins/StdinReader.hs index c1e2724..76e102c 100644 --- a/src/Xmobar/Plugins/StdinReader.hs +++ b/src/Xmobar/Plugins/StdinReader.hs @@ -26,7 +26,7 @@ import System.Exit import System.IO import System.IO.Error (isEOFError) import Xmobar.Run.Exec -import Xmobar.X11.Actions (stripActions) +import Xmobar.Run.Actions (stripActions) import Control.Exception import Control.Monad (forever) diff --git a/src/Xmobar/Plugins/XMonadLog.hs b/src/Xmobar/Plugins/XMonadLog.hs index 0bf62e1..4efd585 100644 --- a/src/Xmobar/Plugins/XMonadLog.hs +++ b/src/Xmobar/Plugins/XMonadLog.hs @@ -21,14 +21,16 @@ import Control.Monad import Graphics.X11 import Graphics.X11.Xlib.Extras import Xmobar.Run.Exec +import Xmobar.Run.Actions (stripActions) + #ifdef UTF8 #undef UTF8 import Codec.Binary.UTF8.String as UTF8 #define UTF8 #endif + import Foreign.C (CChar) import Xmobar.X11.Events (nextEvent') -import Xmobar.X11.Actions (stripActions) data XMonadLog = XMonadLog | UnsafeXMonadLog diff --git a/src/Xmobar/Run/Actions.hs b/src/Xmobar/Run/Actions.hs new file mode 100644 index 0000000..f7d0e45 --- /dev/null +++ b/src/Xmobar/Run/Actions.hs @@ -0,0 +1,36 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Xmobar.Run.Actions +-- Copyright : (c) Alexander Polakov +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A. Ortega Ruiz +-- Stability : unstable +-- Portability : unportable +-- +----------------------------------------------------------------------------- + +module Xmobar.Run.Actions (Button, Action(..), runAction, stripActions) where + +import System.Process (system) +import Control.Monad (void) +import Text.Regex (Regex, subRegex, mkRegex, matchRegex) +import Data.Word (Word32) + +type Button = Word32 + +data Action = Spawn [Button] String + deriving (Eq, Show) + +runAction :: Action -> IO () +runAction (Spawn _ s) = void $ system (s ++ "&") + +stripActions :: String -> String +stripActions s = case matchRegex actionRegex s of + Nothing -> s + Just _ -> stripActions strippedOneLevel + where + strippedOneLevel = subRegex actionRegex s "[action=\\1\\2]\\3[/action]" + +actionRegex :: Regex +actionRegex = mkRegex "`]*)`?( +button=[12345]+)?>(.+)" diff --git a/src/Xmobar/X11/Actions.hs b/src/Xmobar/X11/Actions.hs deleted file mode 100644 index 87c03ed..0000000 --- a/src/Xmobar/X11/Actions.hs +++ /dev/null @@ -1,34 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Xmobar.Actions --- Copyright : (c) Alexander Polakov --- License : BSD-style (see LICENSE) --- --- Maintainer : Jose A. Ortega Ruiz --- Stability : unstable --- Portability : unportable --- ------------------------------------------------------------------------------ - -module Xmobar.X11.Actions (Action(..), runAction, stripActions) where - -import System.Process (system) -import Control.Monad (void) -import Text.Regex (Regex, subRegex, mkRegex, matchRegex) -import Graphics.X11.Types (Button) - -data Action = Spawn [Button] String - deriving (Eq, Show) - -runAction :: Action -> IO () -runAction (Spawn _ s) = void $ system (s ++ "&") - -stripActions :: String -> String -stripActions s = case matchRegex actionRegex s of - Nothing -> s - Just _ -> stripActions strippedOneLevel - where - strippedOneLevel = subRegex actionRegex s "[action=\\1\\2]\\3[/action]" - -actionRegex :: Regex -actionRegex = mkRegex "`]*)`?( +button=[12345]+)?>(.+)" diff --git a/src/Xmobar/X11/Bitmap.hs b/src/Xmobar/X11/Bitmap.hs index c17f9d2..2dd47ac 100644 --- a/src/Xmobar/X11/Bitmap.hs +++ b/src/Xmobar/X11/Bitmap.hs @@ -2,7 +2,7 @@ ----------------------------------------------------------------------------- -- | -- Module : X11.Bitmap --- Copyright : (C) 2013, 2015, 2017, 2018 Alexander Polakov +-- Copyright : (C) 2013, 2015, 2017, 2018, 2022 Alexander Polakov -- License : BSD3 -- -- Maintainer : jao@gnu.org @@ -23,9 +23,9 @@ import Graphics.X11.Xlib import System.Directory (doesFileExist) import System.FilePath (()) import System.Mem.Weak ( addFinalizer ) +import Xmobar.Run.Actions (Action) import Xmobar.X11.ColorCache import Xmobar.X11.Parsers (TextRenderInfo(..), Widget(..)) -import Xmobar.X11.Actions (Action) #ifdef XPM import Xmobar.X11.XPMFile(readXPMFile) diff --git a/src/Xmobar/X11/Draw.hs b/src/Xmobar/X11/Draw.hs index 129701b..30f0b75 100644 --- a/src/Xmobar/X11/Draw.hs +++ b/src/Xmobar/X11/Draw.hs @@ -32,8 +32,8 @@ import Graphics.X11.Xlib hiding (textExtents, textWidth) import Graphics.X11.Xlib.Extras import Xmobar.Config.Types +import Xmobar.Run.Actions (Action(..)) import qualified Xmobar.X11.Bitmap as B -import Xmobar.X11.Actions (Action(..)) import Xmobar.X11.Types import Xmobar.X11.Text import Xmobar.X11.ColorCache diff --git a/src/Xmobar/X11/Parsers.hs b/src/Xmobar/X11/Parsers.hs index 0119208..4688760 100644 --- a/src/Xmobar/X11/Parsers.hs +++ b/src/Xmobar/X11/Parsers.hs @@ -25,14 +25,13 @@ module Xmobar.X11.Parsers ( parseString , Widget(..)) where import Xmobar.Config.Types -import Xmobar.X11.Actions +import Xmobar.Run.Actions import Control.Monad (guard, mzero) import Data.Maybe (fromMaybe) import Data.Int (Int32) import Text.ParserCombinators.Parsec import Text.Read (readMaybe) -import Graphics.X11.Types (Button) import Foreign.C.Types (CInt) data Widget = Icon String | Text String | Hspace Int32 deriving Show -- cgit v1.2.3