1import xcffib
2import struct
3import six
4MAJOR_VERSION = 0
5MINOR_VERSION = 0
6key = xcffib.ExtensionKey("DPMS")
7_events = {}
8_errors = {}
9class GetVersionReply(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("xx2x4xHH")
16        self.bufsize = unpacker.offset - base
17class GetVersionCookie(xcffib.Cookie):
18    reply_type = GetVersionReply
19class CapableReply(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        self.capable, = unpacker.unpack("xx2x4xB23x")
26        self.bufsize = unpacker.offset - base
27class CapableCookie(xcffib.Cookie):
28    reply_type = CapableReply
29class GetTimeoutsReply(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        self.standby_timeout, self.suspend_timeout, self.off_timeout = unpacker.unpack("xx2x4xHHH18x")
36        self.bufsize = unpacker.offset - base
37class GetTimeoutsCookie(xcffib.Cookie):
38    reply_type = GetTimeoutsReply
39class DPMSMode:
40    On = 0
41    Standby = 1
42    Suspend = 2
43    Off = 3
44class InfoReply(xcffib.Reply):
45    def __init__(self, unpacker):
46        if isinstance(unpacker, xcffib.Protobj):
47            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
48        xcffib.Reply.__init__(self, unpacker)
49        base = unpacker.offset
50        self.power_level, self.state = unpacker.unpack("xx2x4xHB21x")
51        self.bufsize = unpacker.offset - base
52class InfoCookie(xcffib.Cookie):
53    reply_type = InfoReply
54class dpmsExtension(xcffib.Extension):
55    def GetVersion(self, client_major_version, client_minor_version, is_checked=True):
56        buf = six.BytesIO()
57        buf.write(struct.pack("=xx2xHH", client_major_version, client_minor_version))
58        return self.send_request(0, buf, GetVersionCookie, is_checked=is_checked)
59    def Capable(self, is_checked=True):
60        buf = six.BytesIO()
61        buf.write(struct.pack("=xx2x"))
62        return self.send_request(1, buf, CapableCookie, is_checked=is_checked)
63    def GetTimeouts(self, is_checked=True):
64        buf = six.BytesIO()
65        buf.write(struct.pack("=xx2x"))
66        return self.send_request(2, buf, GetTimeoutsCookie, is_checked=is_checked)
67    def SetTimeouts(self, standby_timeout, suspend_timeout, off_timeout, is_checked=False):
68        buf = six.BytesIO()
69        buf.write(struct.pack("=xx2xHHH", standby_timeout, suspend_timeout, off_timeout))
70        return self.send_request(3, buf, is_checked=is_checked)
71    def Enable(self, is_checked=False):
72        buf = six.BytesIO()
73        buf.write(struct.pack("=xx2x"))
74        return self.send_request(4, buf, is_checked=is_checked)
75    def Disable(self, is_checked=False):
76        buf = six.BytesIO()
77        buf.write(struct.pack("=xx2x"))
78        return self.send_request(5, buf, is_checked=is_checked)
79    def ForceLevel(self, power_level, is_checked=False):
80        buf = six.BytesIO()
81        buf.write(struct.pack("=xx2xH", power_level))
82        return self.send_request(6, buf, is_checked=is_checked)
83    def Info(self, is_checked=True):
84        buf = six.BytesIO()
85        buf.write(struct.pack("=xx2x"))
86        return self.send_request(7, buf, InfoCookie, is_checked=is_checked)
87xcffib._add_ext(key, dpmsExtension, _events, _errors)
88