haskell - 如何让这个 X11 代码工作?

标签 haskell x11

我试图遵循 tutorial on 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

基本上,我需要创建一个带有 Canvas 的简单窗口,我将在上面画一些线条。

我在该片段中做错了什么?

版本:

X11 - 1.5.0.1
GHC - 6.12.1
OS - Linux Mint 10
Xorg - 1:7.5

最佳答案

X11 绑定(bind) 1.5 版本中存在许多与 64 位正确性相关的错误。这些问题已在 1.6 版本中得到修复,因此升级应该可以解决这些问题。

关于haskell - 如何让这个 X11 代码工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13400289/

相关文章:

haskell - 试图理解 Haskell 中的错误捕获

haskell - haskell上点之间的距离

haskell - Cabal ExitFailure 127 是什么意思?

java - 为什么 Web 应用程序卡在 SwingUtilities.isEventDispatchThread() 上

apache - 使用 PHP 从本地运行的 Apache Web 服务器启动 X 应用程序

ffmpeg - 启用音频时帧速率慢 x11

module - 从包管理器安装 Common Lisp 后,如何使用 CLX/XLIB?

haskell - 如何使用 Haskell 的 mmap 库读取共享内存?

haskell - 如何在Yesod路由处理程序中使用自定义错误处理程序?

C++ 编译错误包括 X11/X.h X11/Xlib.h