我仍在为 Haskell 的 X11 绑定而苦苦挣扎。现在,我想检测用户关闭窗口的事件。到目前为止我最好的尝试:
import Graphics.X11.Xlib
import Graphics.X11.Xlib.Extras
import Control.Concurrent (threadDelay)
import Data.Bits
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 300 200 1 border background
setTextProperty dpy win "Hello World" wM_NAME
mapWindow dpy win
moveWindow dpy win 0 0
selectInput dpy win (structureNotifyMask .|. exposureMask)
updateWin dpy win
updateWin :: Display -> Window -> IO ()
updateWin dpy win = do
sync dpy True
allocaXEvent $ \e -> do
nextEvent dpy e
ev <- getEvent e
putStrLn $ eventName ev
threadDelay (1000000)
updateWin dpy win
但我没有得到事件,而是得到以下输出:
ConfigureNotify
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0.0"
after 26 requests (25 known processed) with 5 events remaining.
这是什么原因造成的?处理它的正确方法是什么?