From fb22226dbca8a167d1458766ebfc949ab5c1a1ef Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 19 Aug 2012 14:50:45 +0200 Subject: Improving the documentation of monitor args Following the discussion of pull request #59 in github. --- readme.md | 288 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 151 insertions(+), 137 deletions(-) diff --git a/readme.md b/readme.md index 026e70a..6af1568 100644 --- a/readme.md +++ b/readme.md @@ -385,16 +385,138 @@ infrastructure. See below Writing a Plugin ## System Monitor Plugins -This is the description of the system monitor plugins that are -installed by default. +This is the description of the system monitor plugins available in +xmobar. Some of them are only installed when an optional build option +is set: we mention that fact, when needed, in their description. Each monitor has an `alias` to be used in the output template. -Monitors have default aliases. +Monitors have default aliases. The sections below describe every +monitor in turn, but before we provide a list of the configuration +options (or *monitor arguments*) they all share. + + +### Default Monitor Arguments + +Monitors accept a common set of arguments, described in the first +subsection below. In additon, some monitors accept additional options +that are specific to them. When specifying the list of arguments in +your configuration, the common options come first, followed by "--", +followed by any monitor-specific options. + +These are the options available for all monitors below: + +- `-t` _string_ Output template + - Template for the monitor output. Field names must be enclosed + between pointy brackets (``) and will be substituted by the + computed values. You can also specify the foreground (and + optionally, background) color for a region by bracketing it + between `` (or ``) and + ``. The rest of the template is output verbatim. + - Long option: `--template` + - Default value: per monitor (see above). +- `-H` _number_ The high threshold. + - Numerical values higher than _number_ will be displayed with the + color specified by `-h` (see below). + - Long option: `--High` + - Default value: 66 +- `-L` _number_ The low threshold. + - Numerical values higher than _number_ and lower than the high + threshold will be displayed with the color specified by `-n` + (see below). Values lower than _number_ will use the `-l` color. + - Long option: `--Low` + - Default value: 33 +- `-h` _color_ High threshold color. + - Color for displaying values above the high threshold. _color_ can + be either a name (e.g. "blue") or an hexadecimal RGB (e.g. + "#FF0000"). + - Long option: `--high` + - Default: none (use the default foreground). +- `-n` _color_ Color for 'normal' values + - Color used for values greater than the low threshold but lower + than the high one. + - Long option: `--normal` + - Default: none (use the default foreground). +- `-l` _color_ The low threshold color + - Color for displaying values below the low threshold. + - Long option: `--low` + - Default: none (use the default foreground). +- `-S` _boolean_ Display optional suffixes + - When set to a true designator ("True", "Yes" or "On"), optional + value suffixes such as the '%' symbol or optional units will be + displayed. + - Long option: `--suffix` + - Default: False. +- `-p` _number_ Percentages padding + - Width, in number of digits, for quantities representing + percentages. For instance `-p 3` means that all percentages + in the monitor will be represented using 3 digits. + - Long option: `--ppad` + - Default value: 0 (don't pad) +- `-d` _number_ Decimal digits + - Number of digits after the decimal period to use in float values. + - Long option: `--ddigits` + - Default value: 0 (display only integer part) +- `-m` _number_ Minimum field width + - Minimum width, in number of characters, of the fields in the + monitor template. Values whose printed representation is shorter + than this value will be padded using the padding characters + given by the `-c` option with the alignment specified by `-a` + (see below). + - Long option: `--minwidth` + - Default: 0 +- `-M` _number_ Maximum field width + - Maximum width, in number of characters, of the fields in the + monitor template. Values whose printed representation is longer + than this value will be truncated. + - Long option: `--maxwidth` + - Default: 0 (no maximum width) +- `-w` _number_ Fixed field width + - All fields will be set to this width, padding or truncating as + needed. + - Long option: `--width` + - Default: 0 (variable width) +- `-c` _string_ + - Characters used for padding. The characters of _string_ are used + cyclically. E.g., with `-P +- -w 6`, a field with value "foo" + will be represented as "+-+foo". + - Long option: `--padchars` + - Default value: " " +- `-a` r|l Field alignment + - Whether to use right (r) or left (l) alignment of field values + when padding. + - Long option: `--align` + - Default value: r (padding to the left) +- `-b` _string_ Bar background + - Characters used, cyclically, to draw the background of bars. + For instance, if you set this option to "·.", an empty bar will + look like this: `·.·.·.·.·.` + - Long option: `--bback` + - Default value: ":" +- `-f` _string_ Bar foreground + - Characters used, cyclically, to draw the foreground of bars. + - Long option: `--bfore` + - Default value: "#" +- `-W` _number_ Bar width + - Total number of characters used to draw bars. + - Long option: `--bwidth` + - Default value: 10 + +Commands' arguments must be set as a list. E.g.: + + Run Weather "EGPF" ["-t", ": C"] 36000 + +In this case xmobar will run the weather monitor, getting information +for the weather station ID EGPF (Glasgow Airport, as a homage to GHC) +every hour (36000 tenth of seconds), with a template that will output +something like: + + Glasgow Airport: 16.0C + ### `Uptime Args RefreshRate` - Aliases to `uptime` -- Args: default monitor arguments (see below). The low and high +- Args: default monitor arguments. The low and high thresholds refer to the number of days. - Variables that can be used with the `-t`/`--template` argument: `days`, `hours`, `minutes`, `seconds`. The total uptime is the @@ -405,7 +527,7 @@ Monitors have default aliases. ### `Weather StationID Args RefreshRate` - Aliases to the Station ID: so `Weather "LIPB" []` can be used in template as `%LIPB%` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `station`, `stationState`, `year`, `month`, `day`, `hour`, `wind`, `visibility`, `skyCondition`, `tempC`, `tempF`, @@ -418,7 +540,7 @@ Monitors have default aliases. - Aliases to the interface name: so `Network "eth0" []` can be used as `%eth0%` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `dev`, `rx`, `tx`, `rxbar`, `txbar`. Reception and transmission rates (`rx` and `tx`) are displayed in Kbytes per second, and you @@ -430,7 +552,7 @@ Monitors have default aliases. - Aliases to the interface name with the suffix "wi": thus, `Wirelss "wlan0" []` can be used as `%wlan0wi%` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `essid`, `quality`, `qualitybar` - Default template: ` ` @@ -441,7 +563,7 @@ Monitors have default aliases. ### `Memory Args RefreshRate` - Aliases to `memory` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `total`, `free`, `buffer`, `cache`, `rest`, `used`, `usedratio`, `usedbar`, `freebar` @@ -450,7 +572,7 @@ Monitors have default aliases. ### `Swap Args RefreshRate` - Aliases to `swap` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `total`, `used`, `free`, `usedratio` - Default template: `Swap: %` @@ -458,7 +580,7 @@ Monitors have default aliases. ### `Cpu Args RefreshRate` - Aliases to `cpu` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `total`, `bar`, `user`, `nice`, `system`, `idle`, `iowait` - Default template: `Cpu: %` @@ -466,7 +588,7 @@ Monitors have default aliases. ### `MultiCpu Args RefreshRate` - Aliases to `multicpu` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `autototal`, `autobar`, `autouser`, `autonice`, `autosystem`, `autoidle`, `total`, `bar`, `user`, `nice`, @@ -487,7 +609,8 @@ Monitors have default aliases. look for the ACPI files of each battery. Example: `["BAT0","BAT1","BAT2"]`. Only the first 3 directories will be searched. -- Args: default monitor arguments (see below), plus the following specif ones: +- Args: default monitor arguments, plus the following + specific ones: - `-O`: string for AC "on" status (default: "On") - `-o`: string for AC "off" status (default: "Off") - `-L`: low power (`watts`) threshold (default: -12) @@ -498,6 +621,8 @@ Monitors have default aliases. - `-p`: color to display positive power (battery charging) - `-f`: file in `/sys/class/power_supply` with AC info (default: "AC/online") + All this options, being specific to the monitor, are to be specified + after a `--` in the argument list (see example below). - Variables that can be used with the `-t`/`--template` argument: `left`, `leftbar`, `timeleft`, `watts`, `acstatus` @@ -512,14 +637,15 @@ Monitors have default aliases. "-L", "-15", "-H", "-5", "-l", "red", "-m", "blue", "-h", "green"] 600 + In the above example, the thresholds before the "--" separator - refer to the `` field, while those after the separator affect - how `` is displayed. + affect only the `` and `` fields, while those after + the separator affect how `` is displayed. ### `TopProc Args RefreshRate` - Aliases to `top` -- Args: default monitor arguments (see below). The low and high +- Args: default monitor arguments. The low and high thresholds (`-L` and `-H`) denote, for memory entries, the percent of the process memory over the total amount of memory currently in use and, for cpu entries, the activity percentage (i.e., the value @@ -536,7 +662,7 @@ Monitors have default aliases. ### `TopMem Args RefreshRate` - Aliases to `topmem` -- Args: default monitor arguments (see below). The low and high +- Args: default monitor arguments. The low and high thresholds (`-L` and `-H`) denote the percent of the process memory over the total amount of memory currently in use. - Variables that can be used with the `-t`/`--template` argument: @@ -553,7 +679,7 @@ Monitors have default aliases. where the template can contain , , , or , or for total, free, used, free percentage and used percentage of the given file system capacity. -- Args: default monitor arguments (see below). `-t`/`--template` is ignored. +- Args: default monitor arguments. `-t`/`--template` is ignored. - Default template: none (you must specify a template for each file system). - Example: @@ -567,7 +693,7 @@ Monitors have default aliases. - Disks: list of pairs of the form (device or mount point, template), where the template can contain , , for total, read and write speed, respectively. -- Args: default monitor arguments (see below). `-t`/`--template` is ignored. +- Args: default monitor arguments. `-t`/`--template` is ignored. - Default template: none (you must specify a template for each file system). - Example: @@ -577,7 +703,7 @@ Monitors have default aliases. - Aliases to "thermaln": so `ThermalZone 0 []` can be used in template as `%thermal0%` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `temp` - Default template: `C` @@ -595,7 +721,7 @@ Monitors have default aliases. - Aliases to the Zone: so `Thermal "THRM" []` can be used in template as `%THRM%` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `temp` - Default template: `Thm: C` @@ -608,7 +734,7 @@ Monitors have default aliases. ### `CpuFreq Args RefreshRate` - Aliases to `cpufreq` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `cpu0`, `cpu1`, .., `cpuN` - Default template: `Freq: GHz` @@ -621,7 +747,7 @@ Monitors have default aliases. ### `CoreTemp Args RefreshRate` - Aliases to `coretemp` -- Args: default monitor arguments (see below) +- Args: default monitor arguments - Variables that can be used with the `-t`/`--template` argument: `core0`, `core1`, .., `coreN` - Default template: `Temp: C` @@ -636,7 +762,7 @@ Monitors have default aliases. - Aliases to the mixer name and element name separated by a colon. Thus, `Volume "default" "Master" [] 10` can be used as `%default:Master%`. -- Args: default monitor arguments (see below). Also accepts: +- Args: default monitor arguments. Also accepts: - `-O` _string_ On string - The string used in place of `` when the mixer element is on. Defaults to "[on]". @@ -669,7 +795,7 @@ Monitors have default aliases. - This monitor will only be compiled if you ask for it using the `with_mpd` flag. It needs [libmpd] 5.0 or later (available on Hackage). - Aliases to `mpd` -- Args: default monitor arguments (see below). In addition you can provide +- Args: default monitor arguments. In addition you can provide `-P`, `-S` and `-Z`, with an string argument, to represent the playing, stopped and paused states in the `statei` template field. The environment variables `MPD_HOST` and `MPD_PORT` are used to configure the @@ -765,7 +891,7 @@ Monitors have default aliases. ### `Brightness Args RefreshRate` - Aliases to `bright` -- Args: default monitor arguments (see below), plus the following specif ones: +- Args: default monitor arguments, plus the following specif ones: - `-D`: directory in `/sys/class/backlight/` with files in it (default: "acpi_video0") - `-C`: file with the current brightness (default: @@ -792,118 +918,6 @@ Monitors have default aliases. Run Kbd [("us(dvorak)", "DV"), ("us", "US")] -## Monitor Plugins Commands Arguments - -These are the arguments that can be used for internal commands in the -`commands` configuration option: - -- `-t` _string_ Output template - - Template for the monitor output. Field names must be enclosed - between pointy brackets (``) and will be substituted by the - computed values. You can also specify the foreground (and - optionally, background) color for a region by bracketing it - between `` (or ``) and - ``. The rest of the template is output verbatim. - - Long option: `--template` - - Default value: per monitor (see above). -- `-H` _number_ The high threshold. - - Numerical values higher than _number_ will be displayed with the - color specified by `-h` (see below). - - Long option: `--High` - - Default value: 66 -- `-L` _number_ The low threshold. - - Numerical values higher than _number_ and lower than the high - threshold will be displayed with the color specified by `-n` - (see below). Values lower than _number_ will use the `-l` color. - - Long option: `--Low` - - Default value: 33 -- `-h` _color_ High threshold color. - - Color for displaying values above the high threshold. _color_ can - be either a name (e.g. "blue") or an hexadecimal RGB (e.g. - "#FF0000"). - - Long option: `--high` - - Default: none (use the default foreground). -- `-n` _color_ Color for 'normal' values - - Color used for values greater than the low threshold but lower - than the high one. - - Long option: `--normal` - - Default: none (use the default foreground). -- `-l` _color_ The low threshold color - - Color for displaying values below the low threshold. - - Long option: `--low` - - Default: none (use the default foreground). -- `-S` _boolean_ Display optional suffixes - - When set to a true designator ("True", "Yes" or "On"), optional - value suffixes such as the '%' symbol or optional units will be - displayed. - - Long option: `--suffix` - - Default: False. -- `-p` _number_ Percentages padding - - Width, in number of digits, for quantities representing - percentages. For instance `-p 3` means that all percentages - in the monitor will be represented using 3 digits. - - Long option: `--ppad` - - Default value: 0 (don't pad) -- `-d` _number_ Decimal digits - - Number of digits after the decimal period to use in float values. - - Long option: `--ddigits` - - Default value: 0 (display only integer part) -- `-m` _number_ Minimum field width - - Minimum width, in number of characters, of the fields in the - monitor template. Values whose printed representation is shorter - than this value will be padded using the padding characters - given by the `-c` option with the alignment specified by `-a` - (see below). - - Long option: `--minwidth` - - Default: 0 -- `-M` _number_ Maximum field width - - Maximum width, in number of characters, of the fields in the - monitor template. Values whose printed representation is longer - than this value will be truncated. - - Long option: `--maxwidth` - - Default: 0 (no maximum width) -- `-w` _number_ Fixed field width - - All fields will be set to this width, padding or truncating as - needed. - - Long option: `--width` - - Default: 0 (variable width) -- `-c` _string_ - - Characters used for padding. The characters of _string_ are used - cyclically. E.g., with `-P +- -w 6`, a field with value "foo" - will be represented as "+-+foo". - - Long option: `--padchars` - - Default value: " " -- `-a` r|l Field alignment - - Whether to use right (r) or left (l) alignment of field values - when padding. - - Long option: `--align` - - Default value: r (padding to the left) -- `-b` _string_ Bar background - - Characters used, cyclically, to draw the background of bars. - For instance, if you set this option to "·.", an empty bar will - look like this: `·.·.·.·.·.` - - Long option: `--bback` - - Default value: ":" -- `-f` _string_ Bar foreground - - Characters used, cyclically, to draw the foreground of bars. - - Long option: `--bfore` - - Default value: "#" -- `-W` _number_ Bar width - - Total number of characters used to draw bars. - - Long option: `--bwidth` - - Default value: 10 - -Commands' arguments must be set as a list. E.g.: - - Run Weather "EGPF" ["-t", ": C"] 36000 - -In this case xmobar will run the weather monitor, getting information -for the weather station ID EGPF (Glasgow Airport, as a homage to GHC) -every hour (36000 tenth of seconds), with a template that will output -something like: - - Glasgow Airport: 16.0C - ## Executing External Commands In order to execute an external command you can either write the -- cgit v1.2.3 From d52278f48d98f116d3a1ebd21000bf80d90b8c9d Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Wed, 22 Aug 2012 17:29:37 +0200 Subject: Allow multiple signals over dbus at once It's easy to implement, since arguments to dbus method calls are handed over as list anyway. It also removes the need for safeHead. Bottom line: extra functionality without extra cost. --- readme.md | 5 +++++ src/IPC/DBus.hs | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 6af1568..7bb7adb 100644 --- a/readme.md +++ b/readme.md @@ -339,6 +339,11 @@ An example using the `dbus-send` command line utility: org.Xmobar.Control.SendSignal \ "string:Toggle" +It is also possible to send multiple signals at once: + # send to another screen, reveal and toggle the persistent flag + dbus-send [..] \ + "string:ChangeScreen" "string:Reveal" "string:TogglePersistent" + ## The Output Template diff --git a/src/IPC/DBus.hs b/src/IPC/DBus.hs index 469a7c6..d755220 100644 --- a/src/IPC/DBus.hs +++ b/src/IPC/DBus.hs @@ -18,13 +18,12 @@ import Prelude hiding (catch) import DBus import DBus.Client -import Control.Monad (join, when) +import Control.Monad (when) import Control.Concurrent import Control.Exception (catch) import System.IO (stderr, hPutStrLn) import Signal -import Plugins.Utils (safeHead) busName :: BusName busName = busName_ "org.Xmobar.Control" @@ -56,8 +55,8 @@ sendSignalMethod mvst = method interfaceName sendSignalName sendSignalMethodCall :: MethodCall -> IO Reply sendSignalMethodCall mc = do - when ( methodCallMember mc == sendSignalName ) $ sendSignal $ - join $ safeHead $ map fromVariant $ methodCallBody mc + when ( methodCallMember mc == sendSignalName ) + $ mapM_ (sendSignal . fromVariant) (methodCallBody mc) return ( replyReturn [] ) sendSignal :: Maybe SignalType -> IO () -- cgit v1.2.3 From 68f9f51cd7e20190e1ef2fd95beaf7c852f11c81 Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Wed, 22 Aug 2012 20:25:29 +0200 Subject: Refactor MVar SignalType to TMVar SignalType Replace MVar with TMVar from the STM package. This is common for ghc now. Since STM is used everywhere else in the src it also adds no additional dependencies. The main reason for this switch is, that readMVar, swapMVar, etc. are only atomically if there is no other producer for this MVar i.e. putMVar. For example readMVar is a combination of putMVar and takeMVar. Due to scheduling and readMVar's non-atomicity it is possible that values written to the MVar appear in the wrong order. Using TMVar fixes this problem, since it allows really atomical read/swap operations. --- src/IPC/DBus.hs | 8 ++++---- src/Signal.hs | 14 +++++++------- src/Xmobar.hs | 21 +++++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/IPC/DBus.hs b/src/IPC/DBus.hs index d755220..60544a9 100644 --- a/src/IPC/DBus.hs +++ b/src/IPC/DBus.hs @@ -19,7 +19,7 @@ import Prelude hiding (catch) import DBus import DBus.Client import Control.Monad (when) -import Control.Concurrent +import Control.Concurrent.STM import Control.Exception (catch) import System.IO (stderr, hPutStrLn) @@ -34,7 +34,7 @@ objectPath = objectPath_ "/org/Xmobar/Control" interfaceName :: InterfaceName interfaceName = interfaceName_ "org.Xmobar.Control" -runIPC :: MVar SignalType -> IO () +runIPC :: TMVar SignalType -> IO () runIPC mvst = catch exportConnection printException where printException :: ClientError -> IO () @@ -44,7 +44,7 @@ runIPC mvst = catch exportConnection printException requestName client busName [ nameDoNotQueue ] export client objectPath [ sendSignalMethod mvst ] -sendSignalMethod :: MVar SignalType -> Method +sendSignalMethod :: TMVar SignalType -> Method sendSignalMethod mvst = method interfaceName sendSignalName (signature_ [variantType $ toVariant $ (undefined :: SignalType)]) (signature_ []) @@ -60,4 +60,4 @@ sendSignalMethod mvst = method interfaceName sendSignalName return ( replyReturn [] ) sendSignal :: Maybe SignalType -> IO () - sendSignal = maybe (return ()) (putMVar mvst) + sendSignal = maybe (return ()) (atomically . putTMVar mvst) diff --git a/src/Signal.hs b/src/Signal.hs index a003859..44fe4f9 100644 --- a/src/Signal.hs +++ b/src/Signal.hs @@ -19,7 +19,7 @@ module Signal where import Data.Typeable (Typeable) -import Control.Concurrent +import Control.Concurrent.STM import Control.Exception hiding (handle) import System.Posix.Signals @@ -52,19 +52,19 @@ parseSignalType :: String -> Maybe SignalType parseSignalType = fmap fst . safeHead . reads -- | Signal handling -setupSignalHandler :: IO (MVar SignalType) +setupSignalHandler :: IO (TMVar SignalType) setupSignalHandler = do - tid <- newEmptyMVar + tid <- newEmptyTMVarIO installHandler sigUSR2 (Catch $ updatePosHandler tid) Nothing installHandler sigUSR1 (Catch $ changeScreenHandler tid) Nothing return tid -updatePosHandler :: MVar SignalType -> IO () +updatePosHandler :: TMVar SignalType -> IO () updatePosHandler sig = do - putMVar sig Reposition + atomically $ putTMVar sig Reposition return () -changeScreenHandler :: MVar SignalType -> IO () +changeScreenHandler :: TMVar SignalType -> IO () changeScreenHandler sig = do - putMVar sig ChangeScreen + atomically $ putTMVar sig ChangeScreen return () diff --git a/src/Xmobar.hs b/src/Xmobar.hs index 2dbba11..79234d2 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -75,7 +75,7 @@ runX :: XConf -> X () -> IO () runX xc f = runReaderT f xc -- | Starts the main event loop and threads -startLoop :: XConf -> MVar SignalType -> [[(Maybe ThreadId, TVar String)]] -> IO () +startLoop :: XConf -> TMVar SignalType -> [[(Maybe ThreadId, TVar String)]] -> IO () startLoop xcfg@(XConf _ _ w _ _) sig vs = do tv <- atomically $ newTVar [] _ <- forkIO (checker tv [] vs sig `catch` @@ -107,16 +107,16 @@ startLoop xcfg@(XConf _ _ w _ _) sig vs = do #endif ev <- getEvent e case ev of - ConfigureEvent {} -> putMVar signal Reposition - ExposeEvent {} -> putMVar signal Wakeup - RRScreenChangeNotifyEvent {} -> putMVar signal Reposition + ConfigureEvent {} -> atomically $ putTMVar signal Reposition + ExposeEvent {} -> atomically $ putTMVar signal Wakeup + RRScreenChangeNotifyEvent {} -> atomically $ putTMVar signal Reposition _ -> return () -- | Send signal to eventLoop every time a var is updated checker :: TVar [String] -> [String] -> [[(Maybe ThreadId, TVar String)]] - -> MVar SignalType + -> TMVar SignalType -> IO () checker tvar ov vs signal = do nval <- atomically $ do @@ -124,16 +124,16 @@ checker tvar ov vs signal = do guard (nv /= ov) writeTVar tvar nv return nv - putMVar signal Wakeup + atomically $ putTMVar signal Wakeup checker tvar nval vs signal where concatV = fmap concat . mapM (readTVar . snd) -- | Continuously wait for a signal from a thread or a interrupt handler -eventLoop :: TVar [String] -> XConf -> MVar SignalType -> IO () +eventLoop :: TVar [String] -> XConf -> TMVar SignalType -> IO () eventLoop tv xc@(XConf d _ w fs cfg) signal = do - typ <- takeMVar signal + typ <- atomically $ takeTMVar signal case typ of Wakeup -> do runX xc (updateWin tv) @@ -186,7 +186,7 @@ eventLoop tv xc@(XConf d _ w fs cfg) signal = do -- | Runs a command as an independent thread and returns its thread id -- and the TVar the command will be writing to. -startCommand :: MVar SignalType +startCommand :: TMVar SignalType -> (Runnable,String,String) -> IO (Maybe ThreadId, TVar String) startCommand sig (com,s,ss) @@ -196,7 +196,8 @@ startCommand sig (com,s,ss) | otherwise = do var <- atomically $ newTVar is let cb str = atomically $ writeTVar var (s ++ str ++ ss) h <- forkIO $ start com cb - _ <- forkIO $ trigger com ( maybe (return ()) (putMVar sig) ) + _ <- forkIO $ trigger com + $ maybe (return ()) (atomically . putTMVar sig) return (Just h,var) where is = s ++ "Updating..." ++ ss -- cgit v1.2.3