Python -Xlib
关于Xlib,网上相关都介绍比较少,只能从库文件那里获取信息啦 http://python-xlib.sourceforge.net/?page=home
基本概念就是:程序和X server建立连接,之后进行通信,Event之类都是通过这个链接进行的。至于Pixmap, Graphic Context之类的,还需要进一步学习。
Sample:
#!/usr/bin/env pyhon
# message.py --example program illustrating use message dialog
#import pygtk
#pygtk.require('2.0')
import gtk
from collections import namedtuple
from Xlib import X, display, Xutil, Xcursorfont
(screenWidth, screenHeight) = gtk.gdk.get_default_root_window().get_size()
disp = display.Display()
rootWindow = disp.screen().root
WM_HINTS = disp.intern_atom("WM_HINTS", True)
WM_STATE = disp.intern_atom("WM_STATE", True)
WM_DESKTOP = disp.intern_atom("_NET_WM_DESKTOP", True)
def enumXlibWindow():
''' enumerate child window of rootWindow'''
return rootWindow.query_tree().children
def findWindowByProperty(xlibWindow, atom=WM_STATE):
''' find Window by property '''
result = xlibWindow.query_tree().children
if not result:
return None
else:
for children in result:
status = children.get_property(atom, WM_HINTS, 0, 0)
if status:
child = children
else:
child = findWindowByProperty(children, atom)
return child
def convertCoord(x, y, width, height):
''' cut out overlop the screen'''
xWidth = x + width
yHeight = y + height
if x < 0 and y > 0 and y < yHeight < screenHeight:
return (0, y, width+x, height)
if x < 0 and yHeight > screenHeight:
return (0, y, width+x, height - (yHeight - screenHeight))
if xWidth > screenWidth and yHeight > screenHeight:
return (x, y, width - (xWidth - screenWidth), height - (yHeight - screenHeight))
if x > 0 and x < xWidth < screenWidth a