我试图按照X11 haskell 库上的教程进行操作,但遇到了一个问题 - 创建的窗口位于屏幕的左下角,而不是左上角,并且绘图(在方法中drawInWin
)似乎没有做任何事情.
#!/usr/bin/runghc -Wall
module Main where
import Graphics.X11.Xlib
import System.Exit (exitWith, ExitCode(..))
import Control.Concurrent (threadDelay)
main :: IO ()
main = do
dpy <- openDisplay ""
let dflt = defaultScreen dpy
border = blackPixel dpy dflt
background = whitePixel dpy dflt
rootw <- rootWindow dpy dflt
win <- createSimpleWindow dpy rootw 0 0 100 100 1 border background
setTextProperty dpy win "Hello World" wM_NAME
mapWindow dpy win
drawInWin dpy win
sync dpy False
threadDelay (10 * 1000000)
exitWith ExitSuccess
drawInWin :: Display -> Window -> IO ()
drawInWin dpy win = do
bgcolor <- initColor dpy "green"
fgcolor <- initColor dpy "blue"
gc <- createGC dpy win
setForeground dpy gc bgcolor
fillRectangle dpy win gc 0 0 100 100
setForeground dpy gc fgcolor
fillRectangle dpy win gc 2 2 96 96
freeGC dpy gc
initColor :: Display -> String -> IO Pixel
initColor dpy color = do
let colormap = defaultColormap dpy (defaultScreen dpy)
(apros,real) <- allocNamedColor dpy colormap color
return $ color_pixel apros
基本上,我需要创建一个带有画布的简单窗口,我将在其上绘制一些线条。
我在那个片段中做错了什么?
版本:
X11 - 1.5.0.1
GHC - 6.12.1
OS - Linux Mint 10
Xorg - 1:7.5