1import xcffib 2import struct 3import six 4MAJOR_VERSION = 1 5MINOR_VERSION = 0 6key = xcffib.ExtensionKey("XEVIE") 7_events = {} 8_errors = {} 9class QueryVersionReply(xcffib.Reply): 10 def __init__(self, unpacker): 11 if isinstance(unpacker, xcffib.Protobj): 12 unpacker = xcffib.MemoryUnpacker(unpacker.pack()) 13 xcffib.Reply.__init__(self, unpacker) 14 base = unpacker.offset 15 self.server_major_version, self.server_minor_version = unpacker.unpack("xx2x4xHH20x") 16 self.bufsize = unpacker.offset - base 17class QueryVersionCookie(xcffib.Cookie): 18 reply_type = QueryVersionReply 19class StartReply(xcffib.Reply): 20 def __init__(self, unpacker): 21 if isinstance(unpacker, xcffib.Protobj): 22 unpacker = xcffib.MemoryUnpacker(unpacker.pack()) 23 xcffib.Reply.__init__(self, unpacker) 24 base = unpacker.offset 25 unpacker.unpack("xx2x4x24x") 26 self.bufsize = unpacker.offset - base 27class StartCookie(xcffib.Cookie): 28 reply_type = StartReply 29class EndReply(xcffib.Reply): 30 def __init__(self, unpacker): 31 if isinstance(unpacker, xcffib.Protobj): 32 unpacker = xcffib.MemoryUnpacker(unpacker.pack()) 33 xcffib.Reply.__init__(self, unpacker) 34 base = unpacker.offset 35 unpacker.unpack("xx2x4x24x") 36 self.bufsize = unpacker.offset - base 37class EndCookie(xcffib.Cookie): 38 reply_type = EndReply 39class Datatype: 40 Unmodified = 0 41 Modified = 1 42class Event(xcffib.Struct): 43 def __init__(self, unpacker): 44 if isinstance(unpacker, xcffib.Protobj): 45 unpacker = xcffib.MemoryUnpacker(unpacker.pack()) 46 xcffib.Struct.__init__(self, unpacker) 47 base = unpacker.offset 48 unpacker.unpack("32x") 49 self.bufsize = unpacker.offset - base 50 def pack(self): 51 buf = six.BytesIO() 52 buf.write(struct.pack("=32x")) 53 return buf.getvalue() 54 fixed_size = 32 55class SendReply(xcffib.Reply): 56 def __init__(self, unpacker): 57 if isinstance(unpacker, xcffib.Protobj): 58 unpacker = xcffib.MemoryUnpacker(unpacker.pack()) 59 xcffib.Reply.__init__(self, unpacker) 60 base = unpacker.offset 61 unpacker.unpack("xx2x4x24x") 62 self.bufsize = unpacker.offset - base 63class SendCookie(xcffib.Cookie): 64 reply_type = SendReply 65class SelectInputReply(xcffib.Reply): 66 def __init__(self, unpacker): 67 if isinstance(unpacker, xcffib.Protobj): 68 unpacker = xcffib.MemoryUnpacker(unpacker.pack()) 69 xcffib.Reply.__init__(self, unpacker) 70 base = unpacker.offset 71 unpacker.unpack("xx2x4x24x") 72 self.bufsize = unpacker.offset - base 73class SelectInputCookie(xcffib.Cookie): 74 reply_type = SelectInputReply 75class xevieExtension(xcffib.Extension): 76 def QueryVersion(self, client_major_version, client_minor_version, is_checked=True): 77 buf = six.BytesIO() 78 buf.write(struct.pack("=xx2xHH", client_major_version, client_minor_version)) 79 return self.send_request(0, buf, QueryVersionCookie, is_checked=is_checked) 80 def Start(self, screen, is_checked=True): 81 buf = six.BytesIO() 82 buf.write(struct.pack("=xx2xI", screen)) 83 return self.send_request(1, buf, StartCookie, is_checked=is_checked) 84 def End(self, cmap, is_checked=True): 85 buf = six.BytesIO() 86 buf.write(struct.pack("=xx2xI", cmap)) 87 return self.send_request(2, buf, EndCookie, is_checked=is_checked) 88 def Send(self, data_type, event, is_checked=True): 89 buf = six.BytesIO() 90 buf.write(struct.pack("=xx2xI64x", data_type)) 91 buf.write(event.pack() if hasattr(event, "pack") else Event.synthetic(*event).pack()) 92 return self.send_request(3, buf, SendCookie, is_checked=is_checked) 93 def SelectInput(self, event_mask, is_checked=True): 94 buf = six.BytesIO() 95 buf.write(struct.pack("=xx2xI", event_mask)) 96 return self.send_request(4, buf, SelectInputCookie, is_checked=is_checked) 97xcffib._add_ext(key, xevieExtension, _events, _errors) 98