Skip to content

Commit 76ac445

Browse files
committed
Add a partial implementation of the XFIXES extension and an example that uses
it.
1 parent ff79f58 commit 76ac445

3 files changed

Lines changed: 150 additions & 0 deletions

File tree

Xlib/ext/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
('RECORD', 'record'),
2828
('Composite', 'composite'),
2929
('RANDR', 'randr'),
30+
('XFIXES', 'xfixes'),
3031
]
3132

3233
__all__ = map(lambda x: x[1], __extensions__)

Xlib/ext/xfixes.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Xlib.ext.xfixes -- XFIXES extension module
2+
#
3+
# Copyright (C) 2010-2011 Outpost Embedded, LLC
4+
# Forest Bond <forest.bond@rapidrollout.com>
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation; either version 2 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program; if not, write to the Free Software
18+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19+
20+
'''
21+
A partial implementation of the XFIXES extension. Only the HideCursor and
22+
ShowCursor requests are provided.
23+
'''
24+
25+
from Xlib.protocol import rq
26+
27+
extname = 'XFIXES'
28+
29+
30+
class QueryVersion(rq.ReplyRequest):
31+
_request = rq.Struct(rq.Card8('opcode'),
32+
rq.Opcode(0),
33+
rq.RequestLength(),
34+
rq.Card32('major_version'),
35+
rq.Card32('minor_version')
36+
)
37+
_reply = rq.Struct(rq.ReplyCode(),
38+
rq.Pad(1),
39+
rq.Card16('sequence_number'),
40+
rq.ReplyLength(),
41+
rq.Card32('major_version'),
42+
rq.Card32('minor_version'),
43+
rq.Pad(16)
44+
)
45+
46+
47+
def query_version(self):
48+
return QueryVersion(display=self.display,
49+
opcode=self.display.get_extension_major(extname),
50+
major_version=4,
51+
minor_version=0)
52+
53+
54+
class HideCursor(rq.Request):
55+
_request = rq.Struct(rq.Card8('opcode'),
56+
rq.Opcode(29),
57+
rq.RequestLength(),
58+
rq.Window('window')
59+
)
60+
61+
def hide_cursor(self):
62+
HideCursor(display=self.display,
63+
opcode=self.display.get_extension_major(extname),
64+
window=self)
65+
66+
67+
class ShowCursor(rq.Request):
68+
_request = rq.Struct(rq.Card8('opcode'),
69+
rq.Opcode(30),
70+
rq.RequestLength(),
71+
rq.Window('window')
72+
)
73+
74+
75+
def show_cursor(self):
76+
ShowCursor(display=self.display,
77+
opcode=self.display.get_extension_major(extname),
78+
window=self)
79+
80+
81+
def init(disp, info):
82+
disp.extension_add_method('display', 'xfixes_query_version', query_version)
83+
disp.extension_add_method('window', 'xfixes_hide_cursor', hide_cursor)
84+
disp.extension_add_method('window', 'xfixes_show_cursor', show_cursor)

examples/xfixes.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/python
2+
#
3+
# examples/xfixes.py -- demonstrate the XFIXES extension
4+
#
5+
# Copyright (C) 2011 Outpost Embedded, LLC
6+
# Forest Bond <forest.bond@rapidrollout.com>
7+
#
8+
# This program is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
#
13+
# This program is distributed in the hope that it will be useful,
14+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
# GNU General Public License for more details.
17+
#
18+
# You should have received a copy of the GNU General Public License
19+
# along with this program; if not, write to the Free Software
20+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
22+
23+
import sys, os
24+
from optparse import OptionParser
25+
26+
# Change path so we find Xlib
27+
sys.path.insert(1, os.path.join(sys.path[0], '..'))
28+
29+
from Xlib.display import Display
30+
31+
32+
def main(argv):
33+
parser = OptionParser()
34+
parser.add_option('--hide-cursor', action='store_true', default=False)
35+
parser.add_option('--show-cursor', action='store_true', default=False)
36+
37+
opts, args = parser.parse_args(argv[1:])
38+
39+
if opts.hide_cursor and opts.show_cursor:
40+
parser.error('--hide-cursor and --show-cursor cannot be combined')
41+
42+
if not any((opts.hide_cursor, opts.show_cursor)):
43+
parser.error('specify --hide-cursor or --show-cursor')
44+
45+
display = Display()
46+
47+
if not display.has_extension('XFIXES'):
48+
if display.query_extension('XFIXES') is None:
49+
print >>sys.stderr, 'XFIXES extension not supported'
50+
return 1
51+
52+
xfixes_version = display.xfixes_query_version()
53+
print >>sys.stderr, 'Found XFIXES version %s.%s' % (
54+
xfixes_version.major_version,
55+
xfixes_version.minor_version,
56+
)
57+
58+
if opts.hide_cursor:
59+
display.screen().root.xfixes_hide_cursor()
60+
elif opts.show_cursor:
61+
display.screen().root.xfixes_hide_cursor()
62+
63+
64+
if __name__ == '__main__':
65+
sys.exit(main(sys.argv))

0 commit comments

Comments
 (0)