summary refs log tree commit diff stats
path: root/tests/x11test.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2008-12-12 14:02:27 +0100
committerAndreas Rumpf <rumpf_a@web.de>2008-12-12 14:02:27 +0100
commitddaedab835fa7ea3457f21a772d636921defdc46 (patch)
tree8f96b5a3a6700704e0a64bdcdedee1d2caf68517 /tests/x11test.nim
parent2cd136cf7a0210e3cfde7a6f8ba32c9f09560047 (diff)
downloadNim-ddaedab835fa7ea3457f21a772d636921defdc46.tar.gz
version 0.7.2
Diffstat (limited to 'tests/x11test.nim')
-rw-r--r--tests/x11test.nim71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/x11test.nim b/tests/x11test.nim
new file mode 100644
index 000000000..2769b6c74
--- /dev/null
+++ b/tests/x11test.nim
@@ -0,0 +1,71 @@
+import xlib, xutil, x, keysym
+
+const
+  WINDOW_WIDTH = 400
+  WINDOW_HEIGHT = 300
+  
+var
+  width, height: int
+  display: PDisplay
+  screen: cint
+  depth: int
+  win: TWindow
+  sizeHints: TXSizeHints
+
+proc create_window = 
+  width = WINDOW_WIDTH
+  height = WINDOW_HEIGHT
+
+  display = XOpenDisplay(nil)
+  if display == nil:
+    echo("Verbindung zum X-Server fehlgeschlagen")
+    quit(1)
+
+  screen = XDefaultScreen(display)
+  depth = XDefaultDepth(display, screen)
+  var rootwin = XRootWindow(display, screen)
+  win = XCreateSimpleWindow(display, rootwin, 100, 10,
+                            width, height, 5,
+                            XBlackPixel(display, screen),
+                            XWhitePixel(display, screen))
+  size_hints.flags = PSize or PMinSize or PMaxSize
+  size_hints.min_width =  width
+  size_hints.max_width =  width
+  size_hints.min_height = height
+  size_hints.max_height = height
+  discard XSetStandardProperties(display, win, "Simple Window", "window",
+                         0, nil, 0, addr(size_hints))
+  discard XSelectInput(display, win, ButtonPressMask or KeyPressMask or 
+                                     PointerMotionMask)
+  discard XMapWindow(display, win)
+
+proc close_window =
+  discard XDestroyWindow(display, win)
+  discard XCloseDisplay(display)
+    
+var
+  xev: TXEvent
+
+proc process_event =
+  var key: TKeySym
+  case int(xev.theType)
+  of KeyPress:
+    key = XLookupKeysym(cast[ptr TXKeyEvent](addr(xev)), 0)
+    if key != 0:
+      echo("keyboard event")
+  of ButtonPressMask, PointerMotionMask:
+    Echo("Mouse event")
+  else: nil
+
+proc eventloop =
+  discard XFlush(display)
+  var num_events = int(XPending(display))
+  while num_events != 0:
+     dec(num_events)
+     discard XNextEvent(display, addr(xev))
+     process_event()
+
+create_window()
+while true:
+  eventloop()
+close_window()