diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2010-05-14 19:17:42 -0400 |
---|---|---|
committer | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2010-05-14 19:17:42 -0400 |
commit | d5be333339bdaa06136b57214a632e77c356a17a (patch) | |
tree | 37fca6f09115db84567fca0500d49f6163ba4251 | |
parent | 1eb1e3d7e749c9a268d3119fc56e90a89c12bf0d (diff) |
Add a utils directory with some helpful Python scripts.
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | utils/Makefile.am | 1 | ||||
-rwxr-xr-x | utils/seevtmon | 106 | ||||
-rwxr-xr-x | utils/selsprop | 64 | ||||
-rwxr-xr-x | utils/selssel | 68 |
6 files changed, 243 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index 1bfdcf4..1af72fa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1 @@ -SUBDIRS=src +SUBDIRS = src utils diff --git a/configure.ac b/configure.ac index d8fe79d..594d5a0 100644 --- a/configure.ac +++ b/configure.ac @@ -5,6 +5,7 @@ AC_PREREQ(2.57) AC_INIT([sedpymgr], 0.9, [ewalsh@tycho.nsa.gov]) AC_CONFIG_SRCDIR([README]) AM_INIT_AUTOMAKE([foreign dist-bzip2]) +AM_PATH_PYTHON AC_CONFIG_HEADERS([src/config.h]) AC_PROG_CC @@ -15,6 +16,7 @@ AC_SUBST([CFLAGS]) # Checks for pkg-config packages PKG_CHECK_MODULES(XCB, xcb) +PKG_CHECK_MODULES(XPYB, xpyb) PKG_CHECK_MODULES(XFIXES, xcb-xfixes) PKG_CHECK_MODULES(XSELINUX, xcb-xselinux) PKG_CHECK_MODULES(X11, x11) @@ -26,7 +28,7 @@ AC_SUBST([SEDPYMGR_LIBS]) SEDPYMGR_CFLAGS="$GTK_CFLAGS" AC_SUBST([SEDPYMGR_CFLAGS]) -AC_CONFIG_FILES([Makefile src/Makefile]) +AC_CONFIG_FILES([Makefile src/Makefile utils/Makefile]) AC_OUTPUT dnl Configuration output diff --git a/utils/Makefile.am b/utils/Makefile.am new file mode 100644 index 0000000..f942d6d --- /dev/null +++ b/utils/Makefile.am @@ -0,0 +1 @@ +nodist_python_PYTHON = selssel selsprop seevtmon diff --git a/utils/seevtmon b/utils/seevtmon new file mode 100755 index 0000000..bc322bb --- /dev/null +++ b/utils/seevtmon @@ -0,0 +1,106 @@ +#!/usr/bin/python + +import sys +import xcb +from xcb.xproto import * +import xcb.xselinux +import xcb.xfixes + +#dont_care_list = [ 273, 344, 345, 386 ] +dont_care_list = [ ] +atom_hash = {} +seln_hash = {} + +def tree_recurse(window): + conn.core.ChangeWindowAttributes(root, CW.EventMask, [ EventMask.SubstructureNotify | EventMask.PropertyChange ]) + + cookie = conn.core.QueryTree(window) + reply = cookie.reply() + + for child in reply.children: + tree_recurse(child) + + +def list_selections(): + cookie = conn.xselinux.ListSelections() + reply = cookie.reply() + + for item in reply.selections: + cookie = conn.core.GetAtomName(item.name) + seln_hash[item.name] = str(cookie.reply().name.buf()) + + conn.xfixes.SelectSelectionInput(root, item.name, 7) + +def op_to_string(state): + if state == Property.NewValue: + return "changed." + else: + return "went bye-bye." + +def win_to_string(window): + cookie = conn.core.GetProperty(False, window, wm_name, 0, 0, 900) + reply = cookie.reply() + return str(reply.value.buf()) + +def show_property_event(event): + if event.atom in dont_care_list: + return + + if not event.atom in atom_hash: + cookie = conn.core.GetAtomName(event.atom) + reply = cookie.reply() + atom_hash[event.atom] = str(reply.name.buf()) + + winname = win_to_string(event.window) + name = atom_hash[event.atom] + state = op_to_string(event.state) + print "%d(%s): Property %s(%d) %s" % (event.window, winname, name, event.atom, state) + +def show_selection_event(event): + name = seln_hash[event.selection] + + if event.subtype == xcb.xfixes.SelectionEvent.SetSelectionOwner: + winname = win_to_string(event.owner) + print "%d(%s) took ownership of %s(%d)" % (event.owner, winname, name, event.selection) + else: + print "Selection %s(%d) has no owner" % (name, event.selection) + + +conn = xcb.connect() +conn.xfixes = conn(xcb.xfixes.key) +conn.xselinux = conn(xcb.xselinux.key) +conn.xselinux.QueryVersionUnchecked(1, 1) +conn.xfixes.QueryVersionUnchecked(4, 0) + + +setup = conn.get_setup() +root = setup.roots[0].root + +cookie = conn.core.InternAtom(False, 7, "WM_NAME") +wm_name = cookie.reply().atom + +tree_recurse(root) +list_selections() + +while True: + try: + event = conn.wait_for_event() + except BadWindow: + continue + except xcb.ProtocolException as error: + print "Protocol error %s received!" % error.__class__.__name__ + print error[0].__dict__ + break + except: + print "Error: %s" % sys.exc_info()[0].__name__ + break + + if isinstance(event, CreateNotifyEvent): + conn.core.ChangeWindowAttributes(event.window, CW.EventMask, [ EventMask.SubstructureNotify | EventMask.PropertyChange ]) + print "Window %d created." % event.window + elif isinstance(event, DestroyNotifyEvent): + print "Window %d destroyed." % event.window + elif isinstance(event, PropertyNotifyEvent): + show_property_event(event) + elif isinstance(event, xcb.xfixes.SelectionNotifyEvent): + show_selection_event(event) diff --git a/utils/selsprop b/utils/selsprop new file mode 100755 index 0000000..654eec3 --- /dev/null +++ b/utils/selsprop @@ -0,0 +1,64 @@ +#!/usr/bin/python + +import sys +import xcb +from xcb.xproto import * +import xcb.xselinux +import xcb.xfixes + +atom_hash = {} + +def get_atom_name(name): + if not name in atom_hash: + cookie = conn.core.GetAtomName(name) + atom_hash[name] = str(cookie.reply().name.buf()) + + return atom_hash[name] + + +def list_properties(window): + cookie = conn.xselinux.ListProperties(window) + reply = cookie.reply() + alist = [] + + for item in reply.properties: + + alist.append("%s: %s" % (get_atom_name(item.name), + str(item.object_context.buf()))) + + alist.sort() + for item in alist: + print item + + +def usage(): + print "Usage: sellsprop [ --root | <0xn> ]" + print "\t--root: list properties on root window" + print "\t<0xn>: list properties on window with hexadecimal ID n" + + +conn = xcb.connect() +conn.xfixes = conn(xcb.xfixes.key) +conn.xselinux = conn(xcb.xselinux.key) +conn.xselinux.QueryVersionUnchecked(1, 1) +conn.xfixes.QueryVersionUnchecked(4, 0) + +setup = conn.get_setup() +root = setup.roots[0].root + +cookie = conn.core.InternAtom(False, 7, "WM_NAME") +wm_name = cookie.reply().atom + +if len(sys.argv[1:]) == 0: + usage() + +elif sys.argv[1] == '--root': + list_properties(root) + +else: + if sys.argv[1].startswith('0x'): + base = 16 + else: + base = 10 + + list_properties(int(sys.argv[1], base)) diff --git a/utils/selssel b/utils/selssel new file mode 100755 index 0000000..4c831ce --- /dev/null +++ b/utils/selssel @@ -0,0 +1,68 @@ +#!/usr/bin/python + +import sys +import xcb +from xcb.xproto import * +import xcb.xselinux +import xcb.xfixes + +atom_hash = {} + +def get_atom_name(name): + if not name in atom_hash: + cookie = conn.core.GetAtomName(name) + atom_hash[name] = str(cookie.reply().name.buf()) + + return atom_hash[name] + +def list_selections(): + cookie = conn.xselinux.ListSelections() + reply = cookie.reply() + alist = [] + + for item in reply.selections: + alist.append("%s (%d): %s" % (get_atom_name(item.name), item.name, + str(item.object_context.buf()))) + + alist.sort() + for item in alist: + print item + + +def win_to_string(window): + cookie = conn.core.GetProperty(False, window, wm_name, 0, 0, 900) + reply = cookie.reply() + return str(reply.value.buf()) + +def detail_selection(name): + cookie = conn.core.GetSelectionOwner(name) + owner = cookie.reply().owner + print "Selection %s (%d) is owned by %d (%s)" % (get_atom_name(name), + name, owner, + win_to_string(owner)) + +def usage(): + print "Usage: sellssel [ --list | <n>... ]" + print "\t--list: list all selection instances" + print "\t<n>: display ownership information for selection n" + + +conn = xcb.connect() +conn.xfixes = conn(xcb.xfixes.key) +conn.xselinux = conn(xcb.xselinux.key) +conn.xselinux.QueryVersionUnchecked(1, 1) +conn.xfixes.QueryVersionUnchecked(4, 0) + +cookie = conn.core.InternAtom(False, 7, "WM_NAME") +wm_name = cookie.reply().atom + +if len(sys.argv[1:]) == 0: + usage() + +elif sys.argv[1] == '--list': + list_selections() + +else: + for arg in sys.argv[1:]: + detail_selection(int(arg)) + |