1# Xlib.ext.xtest -- XTEST extension module
2#
3#    Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
4#
5# This library is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public License
7# as published by the Free Software Foundation; either version 2.1
8# of the License, or (at your option) any later version.
9#
10# This library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13# See the GNU Lesser General Public License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public
16# License along with this library; if not, write to the
17#    Free Software Foundation, Inc.,
18#    59 Temple Place,
19#    Suite 330,
20#    Boston, MA 02111-1307 USA
21
22from Xlib import X
23from Xlib.protocol import rq
24
25extname = 'XTEST'
26
27CurrentCursor = 1
28
29class GetVersion(rq.ReplyRequest):
30    _request = rq.Struct(rq.Card8('opcode'),
31                         rq.Opcode(0),
32                         rq.RequestLength(),
33                         rq.Card8('major_version'),
34                         rq.Pad(1),
35                         rq.Card16('minor_version')
36                         )
37
38    _reply = rq.Struct(rq.Pad(1),
39                       rq.Card8('major_version'),
40                       rq.Card16('sequence_number'),
41                       rq.Pad(4),
42                       rq.Card16('minor_version'),
43                       rq.Pad(22)
44                       )
45
46def get_version(self, major, minor):
47    return GetVersion(display = self.display,
48                      opcode = self.display.get_extension_major(extname),
49                      major_version = major,
50                      minor_version = minor)
51
52
53class CompareCursor(rq.ReplyRequest):
54    _request = rq.Struct(rq.Card8('opcode'),
55                         rq.Opcode(1),
56                         rq.RequestLength(),
57                         rq.Window('window'),
58                         rq.Cursor('cursor', (X.NONE, CurrentCursor)),
59                         )
60
61    _reply = rq.Struct(rq.Pad(1),
62                       rq.Card8('same'),
63                       rq.Card16('sequence_number'),
64                       rq.Pad(28),
65                       )
66
67def compare_cursor(self, cursor):
68    r = CompareCursor(display = self.display,
69                      opcode = self.display.get_extension_major(extname),
70                      window = self.id,
71                      cursor = cursor)
72    return r.same
73
74class FakeInput(rq.Request):
75    _request = rq.Struct(rq.Card8('opcode'),
76                         rq.Opcode(2),
77                         rq.RequestLength(),
78                         rq.Set('event_type', 1, (X.KeyPress,
79                                                  X.KeyRelease,
80                                                  X.ButtonPress,
81                                                  X.ButtonRelease,
82                                                  X.MotionNotify)),
83                         rq.Card8('detail'),
84                         rq.Pad(2),
85                         rq.Card32('time'),
86                         rq.Window('root', (X.NONE, )),
87                         rq.Pad(8),
88                         rq.Int16('x'),
89                         rq.Int16('y'),
90                         rq.Pad(8)
91                         )
92
93def fake_input(self, event_type, detail = 0, time = X.CurrentTime,
94               root = X.NONE, x = 0, y = 0):
95
96    FakeInput(display = self.display,
97              opcode = self.display.get_extension_major(extname),
98              event_type = event_type,
99              detail = detail,
100              time = time,
101              root = root,
102              x = x,
103              y = y)
104
105class GrabControl(rq.Request):
106    _request = rq.Struct(rq.Card8('opcode'),
107                         rq.Opcode(3),
108                         rq.RequestLength(),
109                         rq.Bool('impervious'),
110                         rq.Pad(3)
111                         )
112
113def grab_control(self, impervious):
114    GrabControl(display = self.display,
115                opcode = self.display.get_extension_major(extname),
116                impervious = impervious)
117
118def init(disp, info):
119    disp.extension_add_method('display', 'xtest_get_version', get_version)
120    disp.extension_add_method('window', 'xtest_compare_cursor', compare_cursor)
121    disp.extension_add_method('display', 'xtest_fake_input', fake_input)
122    disp.extension_add_method('display', 'xtest_grab_control', grab_control)
123