Skip to content

Instantly share code, notes, and snippets.

@takaki
Created November 13, 2012 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takaki/4063677 to your computer and use it in GitHub Desktop.
Save takaki/4063677 to your computer and use it in GitHub Desktop.
xpyb sample
# -*- coding: utf-8 -*-
from xcb import xcb
from xcb import xproto
r = [ 20, 20, 60, 60 ]
title = "test"
c = xcb.connect()
s = c.get_setup().roots[0]
g = c.generate_id()
w = s.root
mask = xproto.GC.Foreground | xproto.GC.GraphicsExposures
values = [ s.black_pixel, 0 ]
c.core.CreateGC(g, w, mask, values)
w = c.generate_id()
mask = xproto.CW.BackPixel | xproto.CW.EventMask
values = [ s.white_pixel ,
xproto.EventMask.Exposure | xproto.EventMask.KeyPress]
c.core.CreateWindow(s.root_depth, w, s.root,
10, 10, 100, 100, 1,
xproto.WindowClass.InputOutput, s.root_visual,
mask, values)
c.core.MapWindow(w)
c.core.ChangeProperty(xproto.PropMode.Replace, w,
xproto.Atom.WM_NAME, xproto.Atom.STRING, 8,
len(title), title)
c.flush()
done = False
e = c.wait_for_event()
while not done and e:
if isinstance(e, xproto.ExposeEvent):
c.core.PolyFillRectangle(w, g, 1, r)
c.flush()
elif isinstance(e, xproto.KeyPressEvent):
done = True
break
e = c.wait_for_event()
c.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment