1 # xlibtest.rb - A test of Xlib.pir usage from cardinal
3 # To run this file, execute the following command from the
6 # ../../parrot ../../languages/cardinal/cardinal.pbc xlibtest.rb
8 # (You must have the cardinal pbc already builded).
10 # Press Esc key to exit the program.
12 # Parsing is very slow. Give it a minute to start up.
17 puts 'Display: ' + Xlib::DisplayName()
19 display = Xlib::OpenDisplay('')
21 puts 'Default screen: ' + display.DefaultScreen()
25 white = display.WhitePixel(0)
26 root = display.RootWindow()
27 window = display.CreateSimpleWindow(root, 0, 0, 600, 400, 0, 0, white)
28 window.StoreName("Hello, ruby")
29 window.SelectInput(163919)
33 keysym = Xlib::StringToKeysym('Escape')
34 code_escape = display.KeysymToKeycode(keysym)
36 event = Xlib::newEvent()
43 listline = Array.new()
47 display.NextEvent(event)
52 window.DrawPoint(x, y)
59 listline.push(newline)
63 if type == 6 && pressed
66 if x != lastx || y != lasty
67 window.DrawLine(lastx, lasty, x, y)
74 #puts 'Exposed. Lines: ', +@listline
76 #puts 'Points ', l.elems
81 window.DrawPoint(lx, ly)
87 window.DrawLine(lx, ly, x, y)
97 code = event.keycode()
98 if code == code_escape