diff options
| author | Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com> | 2025-10-23 09:27:13 +0100 |
|---|---|---|
| committer | Enrico Maria De Angelis <enricomaria.dean6elis@gmail.com> | 2025-10-23 09:27:15 +0100 |
| commit | 57e31a571828e387f3b7b1e7414dd62f1783aa4b (patch) | |
| tree | f0ac9529c1e955b94fe1d9f5983c9a7ad820c793 | |
| parent | 9bb8a1e15c5676bbb13c5dfada01f482959949b4 (diff) | |
| download | xmobar-57e31a571828e387f3b7b1e7414dd62f1783aa4b.tar.gz xmobar-57e31a571828e387f3b7b1e7414dd62f1783aa4b.tar.bz2 | |
Accordion: avoid spawing a process to read from pipe
The reason is that this way the issue
https://codeberg.org/Aster89/xnobar/issues/15#issue-2346829 is fixed.
See https://codeberg.org/Aster89/xnobar/issues/15#issuecomment-7864955
for more details.
| -rw-r--r-- | src/Xmobar/Plugins/Accordion.hs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/Xmobar/Plugins/Accordion.hs b/src/Xmobar/Plugins/Accordion.hs index c1967c2..6a1d8e8 100644 --- a/src/Xmobar/Plugins/Accordion.hs +++ b/src/Xmobar/Plugins/Accordion.hs @@ -25,8 +25,9 @@ import Control.Monad.Reader (runReaderT, ask) import Control.Monad.State.Strict (evalStateT, get, modify') import Data.IORef (atomicModifyIORef', newIORef, readIORef, IORef) import Data.Maybe (isJust) +import GHC.IO.Handle.FD (withFileBlocking) import System.Directory (removeFile) -import System.Exit (ExitCode(..)) +import System.IO (IOMode(ReadMode), hGetContents') import System.Process (readProcessWithExitCode) import Xmobar.Run.Exec (Exec(..), tenthSeconds) @@ -74,10 +75,8 @@ instance (Exec a, Read a, Show a) => Exec (Accordion a) where (_, n, _) <- readProcessWithExitCode "uuidgen" [] "" let pipe = "/tmp/accordion-" ++ removeLinebreak n (_, _, _) <- readProcessWithExitCode "mkfifo" [pipe] "" - withAsync (forever $ do (ret, _, _) <- readProcessWithExitCode "cat" [pipe] "" - case ret of - ExitSuccess -> atomicModifyIORef' clicked (const (Just (), ())) - ExitFailure _ -> error "how is this possible?") + withAsync (forever $ do "" <- withFileBlocking pipe ReadMode hGetContents' + atomicModifyIORef' clicked (const (Just (), ()))) (const $ do strRefs <- mapM (newIORef . const "") runnables strRefs' <- mapM (newIORef . const "") shortRunnables @@ -110,4 +109,4 @@ removeLinebreak :: [a] -> [a] removeLinebreak = init attachClick :: String -> String -> String -attachClick file icon = "<action=`echo 1 > " ++ file ++ "`>" ++ icon ++ "</action>" +attachClick file icon = "<action=`echo -n > " ++ file ++ "`>" ++ icon ++ "</action>" |
