summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Thurman <tthurman@gnome.org>2010-05-08 17:21:15 -0400
committerThomas Thurman <tthurman@gnome.org>2010-05-08 17:21:15 -0400
commit6ea48d75acf06d5784720b5a7df48263d1bf487a (patch)
tree02f911821d32c02eb66e203f2a09a09e2b1e09fe
parent440e04541a3dff2db6dc319f8c0a35c38a0515cb (diff)
downloadmetacity-6ea48d75acf06d5784720b5a7df48263d1bf487a.tar.gz
metacity-6ea48d75acf06d5784720b5a7df48263d1bf487a.tar.bz2
Simple X client for playing with
-rw-r--r--tools/mannequin.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/mannequin.py b/tools/mannequin.py
new file mode 100644
index 0000000..30ed854
--- /dev/null
+++ b/tools/mannequin.py
@@ -0,0 +1,91 @@
+# Copyright (c) 2008-2010 Thomas Thurman <tthurman@gnome.org>; GPL 2.0 or later.
+# Originally based around example code in python-xlib
+# by Peter Liljenberg <petli@ctrl-c.liu.se>.
+
+import sys
+import time
+import re
+from Xlib import X
+from Xlib.protocol import display
+from Xlib.protocol.event import ClientMessage
+from Xlib.protocol.request import *
+
+display = display.Display()
+screen = display.info.roots[display.default_screen]
+window = display.allocate_resource_id()
+gc = display.allocate_resource_id()
+
+CreateWindow(display, None,
+ depth = screen.root_depth,
+ wid = window,
+ parent = screen.root,
+ x = 100, y = 100, width = 250, height = 250, border_width = 2,
+ window_class = X.InputOutput, visual = X.CopyFromParent,
+ background_pixel = screen.white_pixel,
+ event_mask = (X.ExposureMask |
+ X.StructureNotifyMask |
+ X.ButtonPressMask |
+ X.ButtonReleaseMask |
+ X.Button1MotionMask),
+ colormap = X.CopyFromParent)
+
+CreateGC(display, None, gc, window)
+
+def do_event():
+ event = display.next_event()
+
+ if event.type == X.DestroyNotify:
+ sys.exit(0)
+
+ print event
+
+for arg in sys.argv[1:]:
+ if arg=='map':
+ MapWindow(display, None, window)
+ elif arg=='unmap':
+ UnmapWindow(display, window=window)
+ elif arg=='sleep':
+ time.sleep(1)
+ elif arg=='event':
+ do_event()
+ elif arg=='flush':
+ display.flush()
+ elif arg=='events':
+ while 1:
+ do_event()
+ elif arg.startswith('send-'):
+ subargs = arg.split('-')
+ values = []
+ for subarg in subargs[1:]:
+ if subarg=='this':
+ values.append(window)
+ elif subarg=='root':
+ values.append(screen.root)
+ elif re.match('^\d+$', subarg):
+ values.append(int(subarg))
+ elif subarg.startswith('0x'):
+ values.append(int(subarg, 16))
+ else:
+ values.append(InternAtom(display=display,
+ name=subarg,
+ only_if_exists=True).atom)
+ if values[-1]==0:
+ print 'Warning: %s was unrecognised' % (subarg)
+
+ event = ClientMessage(window=values[1],
+ client_type=values[2],
+ data=(32,(values[3:])))
+
+ SendEvent(destination = values[0],
+ display = display,
+ propagate=True,
+ event = event,
+ event_mask = X.SubstructureRedirectMask|X.SubstructureNotifyMask)
+ elif arg=='raise':
+ CirculateWindow(display = display,
+ window = window,
+ direction = X.RaiseLowest)
+ else:
+ print 'Unknown argument: ',arg
+
+