summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-11-25 01:40:25 +0000
committerjao <jao@gnu.org>2018-11-25 01:40:25 +0000
commit071794d33443ff76d85be035394103fc8bf48e98 (patch)
treeaf709ba185ca14eefaf1dca66e678f529990ef38 /src
parent0b7b43ef83a2ab6fd894c20e028b9d69372c7266 (diff)
downloadxmobar-071794d33443ff76d85be035394103fc8bf48e98.tar.gz
xmobar-071794d33443ff76d85be035394103fc8bf48e98.tar.bz2
Wee refactoring
Diffstat (limited to 'src')
-rw-r--r--src/lib/Xmobar/EventLoop.hs3
-rw-r--r--src/lib/Xmobar/Plugins/EWMH.hs2
-rw-r--r--src/lib/Xmobar/Plugins/Kbd.hsc2
-rw-r--r--src/lib/Xmobar/Plugins/Locks.hs2
-rw-r--r--src/lib/Xmobar/Plugins/XMonadLog.hs2
-rw-r--r--src/lib/Xmobar/Utils.hs20
-rw-r--r--src/lib/Xmobar/XUtil.hs15
7 files changed, 24 insertions, 22 deletions
diff --git a/src/lib/Xmobar/EventLoop.hs b/src/lib/Xmobar/EventLoop.hs
index 27fcf6d..00f7465 100644
--- a/src/lib/Xmobar/EventLoop.hs
+++ b/src/lib/Xmobar/EventLoop.hs
@@ -45,6 +45,7 @@ import Xmobar.Runnable
import Xmobar.Signal
import Xmobar.Window
import Xmobar.XUtil
+import Xmobar.Utils
import Xmobar.Draw
import Xmobar.Types
@@ -56,8 +57,6 @@ import Graphics.X11.Xft
import Xmobar.IPC.DBus
#endif
--- $main
-
-- | Starts the main event loop and threads
startLoop :: XConf -> TMVar SignalType -> [[([Async ()], TVar String)]]
-> IO ()
diff --git a/src/lib/Xmobar/Plugins/EWMH.hs b/src/lib/Xmobar/Plugins/EWMH.hs
index 363ec90..d4e9c88 100644
--- a/src/lib/Xmobar/Plugins/EWMH.hs
+++ b/src/lib/Xmobar/Plugins/EWMH.hs
@@ -29,7 +29,7 @@ import Codec.Binary.UTF8.String as UTF8
#define UTF8
#endif
import Foreign.C (CChar, CLong)
-import Xmobar.XUtil (nextEvent')
+import Xmobar.Utils (nextEvent')
import Data.List (intersperse, intercalate)
diff --git a/src/lib/Xmobar/Plugins/Kbd.hsc b/src/lib/Xmobar/Plugins/Kbd.hsc
index 372386e..24f07a3 100644
--- a/src/lib/Xmobar/Plugins/Kbd.hsc
+++ b/src/lib/Xmobar/Plugins/Kbd.hsc
@@ -22,7 +22,7 @@ import Foreign.C.Types
import Foreign.C.String
import Xmobar.Plugins
import Control.Monad (forever)
-import Xmobar.XUtil (nextEvent')
+import Xmobar.Utils (nextEvent')
import Data.List (isPrefixOf, findIndex)
import Data.Maybe (fromJust)
diff --git a/src/lib/Xmobar/Plugins/Locks.hs b/src/lib/Xmobar/Plugins/Locks.hs
index 9a971e5..63a7297 100644
--- a/src/lib/Xmobar/Plugins/Locks.hs
+++ b/src/lib/Xmobar/Plugins/Locks.hs
@@ -21,7 +21,7 @@ import Control.Monad
import Graphics.X11.Xlib.Extras
import Xmobar.Plugins
import Xmobar.Plugins.Kbd
-import Xmobar.XUtil (nextEvent')
+import Xmobar.Utils (nextEvent')
data Locks = Locks
deriving (Read, Show)
diff --git a/src/lib/Xmobar/Plugins/XMonadLog.hs b/src/lib/Xmobar/Plugins/XMonadLog.hs
index 6bbba59..95dc558 100644
--- a/src/lib/Xmobar/Plugins/XMonadLog.hs
+++ b/src/lib/Xmobar/Plugins/XMonadLog.hs
@@ -27,7 +27,7 @@ import Codec.Binary.UTF8.String as UTF8
#define UTF8
#endif
import Foreign.C (CChar)
-import Xmobar.XUtil (nextEvent')
+import Xmobar.Utils (nextEvent')
import Xmobar.Actions (stripActions)
data XMonadLog = XMonadLog
diff --git a/src/lib/Xmobar/Utils.hs b/src/lib/Xmobar/Utils.hs
index ce8c4ad..eeb03f6 100644
--- a/src/lib/Xmobar/Utils.hs
+++ b/src/lib/Xmobar/Utils.hs
@@ -17,15 +17,21 @@
------------------------------------------------------------------------------
-module Xmobar.Utils (expandHome, changeLoop, safeHead, hGetLineSafe) where
+module Xmobar.Utils (expandHome, changeLoop, safeHead, hGetLineSafe, nextEvent')
+where
import Control.Monad
+import Control.Concurrent
import Control.Concurrent.STM
+import System.Posix.Types (Fd(..))
import System.Environment
import System.FilePath
import System.IO
+import Graphics.X11.Xlib (
+ Display(..), XEventPtr, nextEvent, pending, connectionNumber)
+
#if defined XFT || defined UTF8
import qualified System.IO as S (hGetLine)
#endif
@@ -55,3 +61,15 @@ changeLoop s f = atomically s >>= go
safeHead :: [a] -> Maybe a
safeHead [] = Nothing
safeHead (x:_) = Just x
+
+-- | A version of nextEvent that does not block in foreign calls.
+nextEvent' :: Display -> XEventPtr -> IO ()
+nextEvent' d p = do
+ pend <- pending d
+ if pend /= 0
+ then nextEvent d p
+ else do
+ threadWaitRead (Fd fd)
+ nextEvent' d p
+ where
+ fd = connectionNumber d
diff --git a/src/lib/Xmobar/XUtil.hs b/src/lib/Xmobar/XUtil.hs
index c4b4531..e70612b 100644
--- a/src/lib/Xmobar/XUtil.hs
+++ b/src/lib/Xmobar/XUtil.hs
@@ -21,10 +21,8 @@ module Xmobar.XUtil
, textExtents
, textWidth
, printString
- , nextEvent'
) where
-import Control.Concurrent
import Control.Monad (when)
import Control.Monad.Trans
import Control.Exception (SomeException, handle)
@@ -34,7 +32,6 @@ import Graphics.X11.Xlib hiding (textExtents, textWidth)
import qualified Graphics.X11.Xlib as Xlib (textExtents, textWidth)
import Graphics.X11.Xlib.Extras
import System.Mem.Weak ( addFinalizer )
-import System.Posix.Types (Fd(..))
#if defined XFT
import Xmobar.MinXft
@@ -161,15 +158,3 @@ printString dpy drw fs@(Xft fonts) _ fc bc x y s al =
drawXftRect draw bc' x (y - a) (1 + xglyphinfo_xOff gi) (a + d + 2)
drawXftString' draw fc' fonts (toInteger x) (toInteger y) s
#endif
-
--- | A version of nextEvent that does not block in foreign calls.
-nextEvent' :: Display -> XEventPtr -> IO ()
-nextEvent' d p = do
- pend <- pending d
- if pend /= 0
- then nextEvent d p
- else do
- threadWaitRead (Fd fd)
- nextEvent' d p
- where
- fd = connectionNumber d