module XMonad.Util.XUtils
(
averagePixels
, createNewWindow
, showWindow
, showWindows
, hideWindow
, hideWindows
, deleteWindow
, deleteWindows
, paintWindow
, paintAndWrite
, paintTextAndIcons
, stringToPixel
, pixelToString
, fi
) where
import Data.Maybe
import XMonad
import XMonad.Util.Font
import XMonad.Util.Image
import Control.Monad
averagePixels :: Pixel -> Pixel -> Double -> X Pixel
averagePixels :: Pixel -> Pixel -> Double -> X Pixel
averagePixels p1 :: Pixel
p1 p2 :: Pixel
p2 f :: Double
f =
do Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
let cm :: Pixel
cm = Display -> Pixel -> Pixel
defaultColormap Display
d (Display -> Pixel
defaultScreen Display
d)
[Color _ r1 :: Word16
r1 g1 :: Word16
g1 b1 :: Word16
b1 _,Color _ r2 :: Word16
r2 g2 :: Word16
g2 b2 :: Word16
b2 _] <- IO [Color] -> X [Color]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO [Color] -> X [Color]) -> IO [Color] -> X [Color]
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> [Color] -> IO [Color]
queryColors Display
d Pixel
cm [Pixel -> Word16 -> Word16 -> Word16 -> Word8 -> Color
Color Pixel
p1 0 0 0 0,Pixel -> Word16 -> Word16 -> Word16 -> Word8 -> Color
Color Pixel
p2 0 0 0 0]
let mn :: a -> a -> b
mn x1 :: a
x1 x2 :: a
x2 = Double -> b
forall a b. (RealFrac a, Integral b) => a -> b
round (a -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
f Double -> Double -> Double
forall a. Num a => a -> a -> a
+ a -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral a
x2 Double -> Double -> Double
forall a. Num a => a -> a -> a
* (1Double -> Double -> Double
forall a. Num a => a -> a -> a
-Double
f))
Color p :: Pixel
p _ _ _ _ <- IO Color -> X Color
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO Color -> X Color) -> IO Color -> X Color
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> Color -> IO Color
allocColor Display
d Pixel
cm (Pixel -> Word16 -> Word16 -> Word16 -> Word8 -> Color
Color 0 (Word16 -> Word16 -> Word16
forall b a a. (Integral b, Integral a, Integral a) => a -> a -> b
mn Word16
r1 Word16
r2) (Word16 -> Word16 -> Word16
forall b a a. (Integral b, Integral a, Integral a) => a -> a -> b
mn Word16
g1 Word16
g2) (Word16 -> Word16 -> Word16
forall b a a. (Integral b, Integral a, Integral a) => a -> a -> b
mn Word16
b1 Word16
b2) 0)
Pixel -> X Pixel
forall (m :: * -> *) a. Monad m => a -> m a
return Pixel
p
createNewWindow :: Rectangle -> Maybe EventMask -> String -> Bool -> X Window
createNewWindow :: Rectangle -> Maybe Pixel -> String -> Bool -> X Pixel
createNewWindow (Rectangle x :: Position
x y :: Position
y w :: Pixel
w h :: Pixel
h) m :: Maybe Pixel
m col :: String
col o :: Bool
o = do
Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
Pixel
rw <- (XConf -> Pixel) -> X Pixel
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Pixel
theRoot
Pixel
c <- Display -> String -> X Pixel
forall (m :: * -> *).
(Functor m, MonadIO m) =>
Display -> String -> m Pixel
stringToPixel Display
d String
col
Pixel
win <- IO Pixel -> X Pixel
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO Pixel -> X Pixel) -> IO Pixel -> X Pixel
forall a b. (a -> b) -> a -> b
$ Display
-> Screen
-> Pixel
-> Position
-> Position
-> Pixel
-> Pixel
-> Pixel
-> Bool
-> IO Pixel
mkWindow Display
d (Display -> Screen
defaultScreenOfDisplay Display
d) Pixel
rw Position
x Position
y Pixel
w Pixel
h Pixel
c Bool
o
case Maybe Pixel
m of
Just em :: Pixel
em -> IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> Pixel -> IO ()
selectInput Display
d Pixel
win Pixel
em
Nothing -> IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> Pixel -> IO ()
selectInput Display
d Pixel
win Pixel
exposureMask
X Bool -> X () -> X ()
whenX (Bool -> X Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> X Bool) -> Bool -> X Bool
forall a b. (a -> b) -> a -> b
$ Maybe Pixel -> Bool
forall a. Maybe a -> Bool
isJust Maybe Pixel
m) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (X () -> X () -> X ()) -> X () -> X () -> X ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip X () -> X () -> X ()
forall a. X a -> X a -> X a
catchX (() -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ do
Pixel
wINDOW_TYPE <- String -> X Pixel
getAtom "_NET_WM_WINDOW_TYPE"
Pixel
dESKTOP <- String -> X Pixel
getAtom "_NET_WM_WINDOW_TYPE_DESKTOP"
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> Pixel -> Pixel -> CInt -> [CLong] -> IO ()
changeProperty32 Display
d Pixel
win Pixel
wINDOW_TYPE Pixel
aTOM CInt
propModeReplace [Pixel -> CLong
forall a b. (Integral a, Num b) => a -> b
fi Pixel
dESKTOP]
Pixel -> X Pixel
forall (m :: * -> *) a. Monad m => a -> m a
return Pixel
win
showWindow :: Window -> X ()
showWindow :: Pixel -> X ()
showWindow w :: Pixel
w = do
Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> IO ()
mapWindow Display
d Pixel
w
showWindows :: [Window] -> X ()
showWindows :: [Pixel] -> X ()
showWindows = (Pixel -> X ()) -> [Pixel] -> X ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Pixel -> X ()
showWindow
hideWindow :: Window -> X ()
hideWindow :: Pixel -> X ()
hideWindow w :: Pixel
w = do
Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> IO ()
unmapWindow Display
d Pixel
w
hideWindows :: [Window] -> X ()
hideWindows :: [Pixel] -> X ()
hideWindows = (Pixel -> X ()) -> [Pixel] -> X ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Pixel -> X ()
hideWindow
deleteWindow :: Window -> X ()
deleteWindow :: Pixel -> X ()
deleteWindow w :: Pixel
w = do
Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> IO ()
destroyWindow Display
d Pixel
w
deleteWindows :: [Window] -> X ()
deleteWindows :: [Pixel] -> X ()
deleteWindows = (Pixel -> X ()) -> [Pixel] -> X ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Pixel -> X ()
deleteWindow
paintWindow :: Window
-> Dimension
-> Dimension
-> Dimension
-> String
-> String
-> X ()
paintWindow :: Pixel -> Pixel -> Pixel -> Pixel -> String -> String -> X ()
paintWindow w :: Pixel
w wh :: Pixel
wh ht :: Pixel
ht bw :: Pixel
bw c :: String
c bc :: String
bc =
Pixel
-> Rectangle
-> Pixel
-> String
-> String
-> Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
-> Maybe (String, String, [((Position, Position), [[Bool]])])
-> X ()
paintWindow' Pixel
w (Position -> Position -> Pixel -> Pixel -> Rectangle
Rectangle 0 0 Pixel
wh Pixel
ht) Pixel
bw String
c String
bc Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
forall a. Maybe a
Nothing Maybe (String, String, [((Position, Position), [[Bool]])])
forall a. Maybe a
Nothing
paintAndWrite :: Window
-> XMonadFont
-> Dimension
-> Dimension
-> Dimension
-> String
-> String
-> String
-> String
-> [Align]
-> [String]
-> X ()
paintAndWrite :: Pixel
-> XMonadFont
-> Pixel
-> Pixel
-> Pixel
-> String
-> String
-> String
-> String
-> [Align]
-> [String]
-> X ()
paintAndWrite w :: Pixel
w fs :: XMonadFont
fs wh :: Pixel
wh ht :: Pixel
ht bw :: Pixel
bw bc :: String
bc borc :: String
borc ffc :: String
ffc fbc :: String
fbc als :: [Align]
als strs :: [String]
strs = do
Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
[(Position, Position)]
strPositions <- [(Align, String)]
-> ((Align, String) -> X (Position, Position))
-> X [(Position, Position)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ([Align] -> [String] -> [(Align, String)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Align]
als [String]
strs) (((Align, String) -> X (Position, Position))
-> X [(Position, Position)])
-> ((Align, String) -> X (Position, Position))
-> X [(Position, Position)]
forall a b. (a -> b) -> a -> b
$ \(al :: Align
al, str :: String
str) ->
Display
-> XMonadFont
-> Rectangle
-> Align
-> String
-> X (Position, Position)
forall (m :: * -> *).
(Functor m, MonadIO m) =>
Display
-> XMonadFont
-> Rectangle
-> Align
-> String
-> m (Position, Position)
stringPosition Display
d XMonadFont
fs (Position -> Position -> Pixel -> Pixel -> Rectangle
Rectangle 0 0 Pixel
wh Pixel
ht) Align
al String
str
let ms :: Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
ms = (XMonadFont, String, String, [(String, (Position, Position))])
-> Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
forall a. a -> Maybe a
Just (XMonadFont
fs,String
ffc,String
fbc, [String]
-> [(Position, Position)] -> [(String, (Position, Position))]
forall a b. [a] -> [b] -> [(a, b)]
zip [String]
strs [(Position, Position)]
strPositions)
Pixel
-> Rectangle
-> Pixel
-> String
-> String
-> Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
-> Maybe (String, String, [((Position, Position), [[Bool]])])
-> X ()
paintWindow' Pixel
w (Position -> Position -> Pixel -> Pixel -> Rectangle
Rectangle 0 0 Pixel
wh Pixel
ht) Pixel
bw String
bc String
borc Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
ms Maybe (String, String, [((Position, Position), [[Bool]])])
forall a. Maybe a
Nothing
paintTextAndIcons :: Window
-> XMonadFont
-> Dimension
-> Dimension
-> Dimension
-> String
-> String
-> String
-> String
-> [Align]
-> [String]
-> [Placement]
-> [[[Bool]]]
-> X ()
paintTextAndIcons :: Pixel
-> XMonadFont
-> Pixel
-> Pixel
-> Pixel
-> String
-> String
-> String
-> String
-> [Align]
-> [String]
-> [Placement]
-> [[[Bool]]]
-> X ()
paintTextAndIcons w :: Pixel
w fs :: XMonadFont
fs wh :: Pixel
wh ht :: Pixel
ht bw :: Pixel
bw bc :: String
bc borc :: String
borc ffc :: String
ffc fbc :: String
fbc als :: [Align]
als strs :: [String]
strs i_als :: [Placement]
i_als icons :: [[[Bool]]]
icons = do
Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
[(Position, Position)]
strPositions <- [(Align, String)]
-> ((Align, String) -> X (Position, Position))
-> X [(Position, Position)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ([Align] -> [String] -> [(Align, String)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Align]
als [String]
strs) (((Align, String) -> X (Position, Position))
-> X [(Position, Position)])
-> ((Align, String) -> X (Position, Position))
-> X [(Position, Position)]
forall a b. (a -> b) -> a -> b
$ \(al :: Align
al, str :: String
str) ->
Display
-> XMonadFont
-> Rectangle
-> Align
-> String
-> X (Position, Position)
forall (m :: * -> *).
(Functor m, MonadIO m) =>
Display
-> XMonadFont
-> Rectangle
-> Align
-> String
-> m (Position, Position)
stringPosition Display
d XMonadFont
fs (Position -> Position -> Pixel -> Pixel -> Rectangle
Rectangle 0 0 Pixel
wh Pixel
ht) Align
al String
str
let iconPositions :: [(Position, Position)]
iconPositions = ((Placement, [[Bool]]) -> (Position, Position))
-> [(Placement, [[Bool]])] -> [(Position, Position)]
forall a b. (a -> b) -> [a] -> [b]
map ( \(al :: Placement
al, icon :: [[Bool]]
icon) -> Rectangle -> Placement -> [[Bool]] -> (Position, Position)
iconPosition (Position -> Position -> Pixel -> Pixel -> Rectangle
Rectangle 0 0 Pixel
wh Pixel
ht) Placement
al [[Bool]]
icon ) ([Placement] -> [[[Bool]]] -> [(Placement, [[Bool]])]
forall a b. [a] -> [b] -> [(a, b)]
zip [Placement]
i_als [[[Bool]]]
icons)
ms :: Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
ms = (XMonadFont, String, String, [(String, (Position, Position))])
-> Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
forall a. a -> Maybe a
Just (XMonadFont
fs,String
ffc,String
fbc, [String]
-> [(Position, Position)] -> [(String, (Position, Position))]
forall a b. [a] -> [b] -> [(a, b)]
zip [String]
strs [(Position, Position)]
strPositions)
is :: Maybe (String, String, [((Position, Position), [[Bool]])])
is = (String, String, [((Position, Position), [[Bool]])])
-> Maybe (String, String, [((Position, Position), [[Bool]])])
forall a. a -> Maybe a
Just (String
ffc, String
fbc, [(Position, Position)]
-> [[[Bool]]] -> [((Position, Position), [[Bool]])]
forall a b. [a] -> [b] -> [(a, b)]
zip [(Position, Position)]
iconPositions [[[Bool]]]
icons)
Pixel
-> Rectangle
-> Pixel
-> String
-> String
-> Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
-> Maybe (String, String, [((Position, Position), [[Bool]])])
-> X ()
paintWindow' Pixel
w (Position -> Position -> Pixel -> Pixel -> Rectangle
Rectangle 0 0 Pixel
wh Pixel
ht) Pixel
bw String
bc String
borc Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
ms Maybe (String, String, [((Position, Position), [[Bool]])])
is
paintWindow' :: Window -> Rectangle -> Dimension -> String -> String
-> Maybe (XMonadFont,String,String,[(String, (Position, Position))])
-> Maybe (String, String, [((Position, Position), [[Bool]])]) -> X ()
paintWindow' :: Pixel
-> Rectangle
-> Pixel
-> String
-> String
-> Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
-> Maybe (String, String, [((Position, Position), [[Bool]])])
-> X ()
paintWindow' win :: Pixel
win (Rectangle _ _ wh :: Pixel
wh ht :: Pixel
ht) bw :: Pixel
bw color :: String
color b_color :: String
b_color strStuff :: Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
strStuff iconStuff :: Maybe (String, String, [((Position, Position), [[Bool]])])
iconStuff = do
Display
d <- (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
Pixel
p <- IO Pixel -> X Pixel
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO Pixel -> X Pixel) -> IO Pixel -> X Pixel
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> Pixel -> Pixel -> CInt -> IO Pixel
createPixmap Display
d Pixel
win Pixel
wh Pixel
ht (Screen -> CInt
defaultDepthOfScreen (Screen -> CInt) -> Screen -> CInt
forall a b. (a -> b) -> a -> b
$ Display -> Screen
defaultScreenOfDisplay Display
d)
GC
gc <- IO GC -> X GC
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO GC -> X GC) -> IO GC -> X GC
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> IO GC
createGC Display
d Pixel
p
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> GC -> Bool -> IO ()
setGraphicsExposures Display
d GC
gc Bool
False
[color' :: Pixel
color',b_color' :: Pixel
b_color'] <- (String -> X Pixel) -> [String] -> X [Pixel]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Display -> String -> X Pixel
forall (m :: * -> *).
(Functor m, MonadIO m) =>
Display -> String -> m Pixel
stringToPixel Display
d) [String
color,String
b_color]
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> GC -> Pixel -> IO ()
setForeground Display
d GC
gc Pixel
b_color'
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display
-> Pixel -> GC -> Position -> Position -> Pixel -> Pixel -> IO ()
fillRectangle Display
d Pixel
p GC
gc 0 0 Pixel
wh Pixel
ht
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> GC -> Pixel -> IO ()
setForeground Display
d GC
gc Pixel
color'
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display
-> Pixel -> GC -> Position -> Position -> Pixel -> Pixel -> IO ()
fillRectangle Display
d Pixel
p GC
gc (Pixel -> Position
forall a b. (Integral a, Num b) => a -> b
fi Pixel
bw) (Pixel -> Position
forall a b. (Integral a, Num b) => a -> b
fi Pixel
bw) (Pixel
wh Pixel -> Pixel -> Pixel
forall a. Num a => a -> a -> a
- (Pixel
bw Pixel -> Pixel -> Pixel
forall a. Num a => a -> a -> a
* 2)) (Pixel
ht Pixel -> Pixel -> Pixel
forall a. Num a => a -> a -> a
- (Pixel
bw Pixel -> Pixel -> Pixel
forall a. Num a => a -> a -> a
* 2))
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
-> Bool
forall a. Maybe a -> Bool
isJust Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
strStuff) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ do
let (xmf :: XMonadFont
xmf,fc :: String
fc,bc :: String
bc,strAndPos :: [(String, (Position, Position))]
strAndPos) = Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
-> (XMonadFont, String, String, [(String, (Position, Position))])
forall a. HasCallStack => Maybe a -> a
fromJust Maybe
(XMonadFont, String, String, [(String, (Position, Position))])
strStuff
[(String, (Position, Position))]
-> ((String, (Position, Position)) -> X ()) -> X ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(String, (Position, Position))]
strAndPos (((String, (Position, Position)) -> X ()) -> X ())
-> ((String, (Position, Position)) -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \(s :: String
s, (x :: Position
x, y :: Position
y)) ->
Display
-> Pixel
-> XMonadFont
-> GC
-> String
-> String
-> Position
-> Position
-> String
-> X ()
forall (m :: * -> *).
(Functor m, MonadIO m) =>
Display
-> Pixel
-> XMonadFont
-> GC
-> String
-> String
-> Position
-> Position
-> String
-> m ()
printStringXMF Display
d Pixel
p XMonadFont
xmf GC
gc String
fc String
bc Position
x Position
y String
s
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Maybe (String, String, [((Position, Position), [[Bool]])]) -> Bool
forall a. Maybe a -> Bool
isJust Maybe (String, String, [((Position, Position), [[Bool]])])
iconStuff) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ do
let (fc :: String
fc, bc :: String
bc, iconAndPos :: [((Position, Position), [[Bool]])]
iconAndPos) = Maybe (String, String, [((Position, Position), [[Bool]])])
-> (String, String, [((Position, Position), [[Bool]])])
forall a. HasCallStack => Maybe a -> a
fromJust Maybe (String, String, [((Position, Position), [[Bool]])])
iconStuff
[((Position, Position), [[Bool]])]
-> (((Position, Position), [[Bool]]) -> X ()) -> X ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [((Position, Position), [[Bool]])]
iconAndPos ((((Position, Position), [[Bool]]) -> X ()) -> X ())
-> (((Position, Position), [[Bool]]) -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \((x :: Position
x, y :: Position
y), icon :: [[Bool]]
icon) ->
Display
-> Pixel
-> GC
-> String
-> String
-> Position
-> Position
-> [[Bool]]
-> X ()
forall (m :: * -> *).
(Functor m, MonadIO m) =>
Display
-> Pixel
-> GC
-> String
-> String
-> Position
-> Position
-> [[Bool]]
-> m ()
drawIcon Display
d Pixel
p GC
gc String
fc String
bc Position
x Position
y [[Bool]]
icon
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display
-> Pixel
-> Pixel
-> GC
-> Position
-> Position
-> Pixel
-> Pixel
-> Position
-> Position
-> IO ()
copyArea Display
d Pixel
p Pixel
win GC
gc 0 0 Pixel
wh Pixel
ht 0 0
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Pixel -> IO ()
freePixmap Display
d Pixel
p
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> GC -> IO ()
freeGC Display
d GC
gc
mkWindow :: Display -> Screen -> Window -> Position
-> Position -> Dimension -> Dimension -> Pixel -> Bool -> IO Window
mkWindow :: Display
-> Screen
-> Pixel
-> Position
-> Position
-> Pixel
-> Pixel
-> Pixel
-> Bool
-> IO Pixel
mkWindow d :: Display
d s :: Screen
s rw :: Pixel
rw x :: Position
x y :: Position
y w :: Pixel
w h :: Pixel
h p :: Pixel
p o :: Bool
o = do
let visual :: Visual
visual = Screen -> Visual
defaultVisualOfScreen Screen
s
attrmask :: Pixel
attrmask = Pixel
cWOverrideRedirect Pixel -> Pixel -> Pixel
forall a. Bits a => a -> a -> a
.|. Pixel
cWBackPixel Pixel -> Pixel -> Pixel
forall a. Bits a => a -> a -> a
.|. Pixel
cWBorderPixel
(Ptr SetWindowAttributes -> IO Pixel) -> IO Pixel
forall a. (Ptr SetWindowAttributes -> IO a) -> IO a
allocaSetWindowAttributes ((Ptr SetWindowAttributes -> IO Pixel) -> IO Pixel)
-> (Ptr SetWindowAttributes -> IO Pixel) -> IO Pixel
forall a b. (a -> b) -> a -> b
$
\attributes :: Ptr SetWindowAttributes
attributes -> do
Ptr SetWindowAttributes -> Bool -> IO ()
set_override_redirect Ptr SetWindowAttributes
attributes Bool
o
Ptr SetWindowAttributes -> Pixel -> IO ()
set_border_pixel Ptr SetWindowAttributes
attributes Pixel
p
Ptr SetWindowAttributes -> Pixel -> IO ()
set_background_pixel Ptr SetWindowAttributes
attributes Pixel
p
Display
-> Pixel
-> Position
-> Position
-> Pixel
-> Pixel
-> CInt
-> CInt
-> CInt
-> Visual
-> Pixel
-> Ptr SetWindowAttributes
-> IO Pixel
createWindow Display
d Pixel
rw Position
x Position
y Pixel
w Pixel
h 0 (Screen -> CInt
defaultDepthOfScreen Screen
s)
CInt
inputOutput Visual
visual Pixel
attrmask Ptr SetWindowAttributes
attributes