#!/usr/bin/env python3 """Copy an Xcursor theme, keeping only the images of one nominal size. Usage: tools/xcursor_trim.py SRC_DIR DST_DIR [SIZE] Used once to import assets/cursors/adwaita/ from the host's adwaita-cursors package (/usr/share/icons/Adwaita/cursors). Symlinks (legacy X11 aliases) are skipped; every regular file is rewritten as a valid Xcursor file that holds only the SIZE (default 24) image chunks, so the tree does not carry the 30..96 px images (12 MB for the whole theme, mostly the animated wait/progress spinners). Comment chunks are dropped. """ import os import struct import sys XCUR_IMAGE = 0xFFFD0002 def trim(data, size): magic, hdr, version, ntoc = struct.unpack_from('<4sIII', data, 0) if magic != b'Xcur': raise ValueError('not an Xcursor file') chunks = [] for i in range(ntoc): typ, sub, pos = struct.unpack_from(' 3 else 24 os.makedirs(dst, exist_ok=True) for name in sorted(os.listdir(src)): path = os.path.join(src, name) if os.path.islink(path) or not os.path.isfile(path): continue with open(path, 'rb') as f: data = f.read() try: out = trim(data, size) except ValueError as e: print('skip %s: %s' % (name, e)) continue with open(os.path.join(dst, name), 'wb') as f: f.write(out) if __name__ == '__main__': main()