|
| 1 | +# $Id: xtest.py,v 1.1 2000/08/21 10:03:45 petli Exp $ |
| 2 | +# |
| 3 | +# Xlib.ext.composite -- Composite extension module |
| 4 | +# |
| 5 | +# Copyright (C) 2007 Peter Liljenberg <peter.liljenberg@gmail.com> |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation; either version 2 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program; if not, write to the Free Software |
| 19 | +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | + |
| 21 | +"""Composite extension, allowing windows to be rendered to off-screen |
| 22 | +storage. |
| 23 | +
|
| 24 | +For detailed description, see the protocol specification at |
| 25 | +http://freedesktop.org/wiki/Software/CompositeExt |
| 26 | +
|
| 27 | +By itself this extension is not very useful, it is intended to be used |
| 28 | +together with the DAMAGE and XFIXES extensions. Typically you would |
| 29 | +also need RENDER or glX or some similar method of creating fancy |
| 30 | +graphics. |
| 31 | +""" |
| 32 | + |
| 33 | +from Xlib import X |
| 34 | +from Xlib.protocol import rq |
| 35 | +from Xlib.xobject import drawable |
| 36 | + |
| 37 | +extname = 'Composite' |
| 38 | + |
| 39 | +RedirectAutomatic = 0 |
| 40 | +RedirectManual = 1 |
| 41 | + |
| 42 | +class QueryVersion(rq.ReplyRequest): |
| 43 | + _request = rq.Struct( |
| 44 | + rq.Card8('opcode'), |
| 45 | + rq.Opcode(0), |
| 46 | + rq.RequestLength(), |
| 47 | + rq.Card32('major_version'), |
| 48 | + rq.Card32('minor_version') |
| 49 | + ) |
| 50 | + |
| 51 | + _reply = rq.Struct( |
| 52 | + rq.ReplyCode(), |
| 53 | + rq.Pad(1), |
| 54 | + rq.Card16('sequence_number'), |
| 55 | + rq.ReplyLength(), |
| 56 | + rq.Card32('major_version'), |
| 57 | + rq.Card32('minor_version'), |
| 58 | + rq.Pad(16), |
| 59 | + ) |
| 60 | + |
| 61 | +def query_version(self): |
| 62 | + return QueryVersion( |
| 63 | + display = self.display, |
| 64 | + opcode = self.display.get_extension_major(extname), |
| 65 | + ) |
| 66 | + |
| 67 | + |
| 68 | +class RedirectWindow(rq.Request): |
| 69 | + _request = rq.Struct( |
| 70 | + rq.Card8('opcode'), |
| 71 | + rq.Opcode(1), |
| 72 | + rq.RequestLength(), |
| 73 | + rq.Window('window'), |
| 74 | + rq.Set('update', 1, (RedirectAutomatic, RedirectManual)), |
| 75 | + rq.Pad(3), |
| 76 | + ) |
| 77 | + |
| 78 | +def redirect_window(self, update): |
| 79 | + """Redirect the hierarchy starting at this window to off-screen |
| 80 | + storage. |
| 81 | + """ |
| 82 | + RedirectWindow(display = self.display, |
| 83 | + opcode = self.display.get_extension_major(extname), |
| 84 | + window = self, |
| 85 | + update = update, |
| 86 | + ) |
| 87 | + |
| 88 | + |
| 89 | +class RedirectSubwindows(rq.Request): |
| 90 | + _request = rq.Struct( |
| 91 | + rq.Card8('opcode'), |
| 92 | + rq.Opcode(2), |
| 93 | + rq.RequestLength(), |
| 94 | + rq.Window('window'), |
| 95 | + rq.Set('update', 1, (RedirectAutomatic, RedirectManual)), |
| 96 | + rq.Pad(3), |
| 97 | + ) |
| 98 | + |
| 99 | +def redirect_subwindows(self, update): |
| 100 | + """Redirect the hierarchies starting at all current and future |
| 101 | + children to this window to off-screen storage. |
| 102 | + """ |
| 103 | + RedirectSubwindows(display = self.display, |
| 104 | + opcode = self.display.get_extension_major(extname), |
| 105 | + window = self, |
| 106 | + update = update, |
| 107 | + ) |
| 108 | + |
| 109 | + |
| 110 | +class UnredirectWindow(rq.Request): |
| 111 | + _request = rq.Struct( |
| 112 | + rq.Card8('opcode'), |
| 113 | + rq.Opcode(3), |
| 114 | + rq.RequestLength(), |
| 115 | + rq.Window('window'), |
| 116 | + rq.Set('update', 1, (RedirectAutomatic, RedirectManual)), |
| 117 | + rq.Pad(3), |
| 118 | + ) |
| 119 | + |
| 120 | +def unredirect_window(self, update): |
| 121 | + """Stop redirecting this window hierarchy. |
| 122 | + """ |
| 123 | + UnredirectWindow(display = self.display, |
| 124 | + opcode = self.display.get_extension_major(extname), |
| 125 | + window = self, |
| 126 | + update = update, |
| 127 | + ) |
| 128 | + |
| 129 | + |
| 130 | +class UnredirectSubindows(rq.Request): |
| 131 | + _request = rq.Struct( |
| 132 | + rq.Card8('opcode'), |
| 133 | + rq.Opcode(4), |
| 134 | + rq.RequestLength(), |
| 135 | + rq.Window('window'), |
| 136 | + rq.Set('update', 1, (RedirectAutomatic, RedirectManual)), |
| 137 | + rq.Pad(3), |
| 138 | + ) |
| 139 | + |
| 140 | +def unredirect_subwindows(self, update): |
| 141 | + """Stop redirecting the hierarchies of children to this window. |
| 142 | + """ |
| 143 | + RedirectWindow(display = self.display, |
| 144 | + opcode = self.display.get_extension_major(extname), |
| 145 | + window = self, |
| 146 | + update = update, |
| 147 | + ) |
| 148 | + |
| 149 | + |
| 150 | +class CreateRegionFromBorderClip(rq.Request): |
| 151 | + _request = rq.Struct( |
| 152 | + rq.Card8('opcode'), |
| 153 | + rq.Opcode(5), |
| 154 | + rq.RequestLength(), |
| 155 | + rq.Card32('region'), # FIXME: this should be a Region from XFIXES extension |
| 156 | + rq.Window('window'), |
| 157 | + ) |
| 158 | + |
| 159 | +def create_region_from_border_clip(self): |
| 160 | + """Create a region of the border clip of the window, i.e. the area |
| 161 | + that is not clipped by the parent and any sibling windows. |
| 162 | + """ |
| 163 | + |
| 164 | + rid = self.display.allocate_resource_id() |
| 165 | + CreateRegionFromBorderClip( |
| 166 | + display = self.display, |
| 167 | + opcode = self.display.get_extension_major(extname), |
| 168 | + region = rid, |
| 169 | + window = self, |
| 170 | + ) |
| 171 | + |
| 172 | + # FIXME: create Region object and return it |
| 173 | + return rid |
| 174 | + |
| 175 | + |
| 176 | +class NameWindowPixmap(rq.Request): |
| 177 | + _request = rq.Struct( |
| 178 | + rq.Card8('opcode'), |
| 179 | + rq.Opcode(6), |
| 180 | + rq.RequestLength(), |
| 181 | + rq.Window('window'), |
| 182 | + rq.Pixmap('pixmap'), |
| 183 | + ) |
| 184 | + |
| 185 | +def name_window_pixmap(self): |
| 186 | + """Create a new pixmap that refers to the off-screen storage of |
| 187 | + the window, including its border. |
| 188 | +
|
| 189 | + This pixmap will remain allocated until freed whatever happens |
| 190 | + with the window. However, the window will get a new off-screen |
| 191 | + pixmap every time it is mapped or resized, so to keep track of the |
| 192 | + contents you must listen for these events and get a new pixmap |
| 193 | + after them. |
| 194 | + """ |
| 195 | + |
| 196 | + pid = self.display.allocate_resource_id() |
| 197 | + NameWindowPixmap(display = self.display, |
| 198 | + opcode = self.display.get_extension_major(extname), |
| 199 | + window = self, |
| 200 | + pixmap = pid, |
| 201 | + ) |
| 202 | + |
| 203 | + cls = self.display.get_resource_class('pixmap', drawable.Pixmap) |
| 204 | + return cls(self.display, pid, owner = 1) |
| 205 | + |
| 206 | + |
| 207 | +def init(disp, info): |
| 208 | + disp.extension_add_method('display', |
| 209 | + 'composite_query_version', |
| 210 | + query_version) |
| 211 | + |
| 212 | + disp.extension_add_method('window', |
| 213 | + 'composite_redirect_window', |
| 214 | + redirect_window) |
| 215 | + |
| 216 | + disp.extension_add_method('window', |
| 217 | + 'composite_redirect_subwindows', |
| 218 | + redirect_subwindows) |
| 219 | + |
| 220 | + disp.extension_add_method('window', |
| 221 | + 'composite_unredirect_window', |
| 222 | + unredirect_window) |
| 223 | + |
| 224 | + disp.extension_add_method('window', |
| 225 | + 'composite_unredirect_subwindows', |
| 226 | + unredirect_subwindows) |
| 227 | + |
| 228 | + disp.extension_add_method('window', |
| 229 | + 'composite_create_region_from_border_clip', |
| 230 | + create_region_from_border_clip) |
| 231 | + |
| 232 | + disp.extension_add_method('window', |
| 233 | + 'composite_name_window_pixmap', |
| 234 | + name_window_pixmap) |
0 commit comments