X11::P...DAMAGE(3pm)
π X11::Protocol::Ext::DAMAGE β drawing notifications π
okay so bestie, welcome to the DAMAGE page π this is from the User Contributed Perl Documentation crowd (the manual is literally titled X11::P...DAMAGE(3pm), cute of them), and it's all about the X11 DAMAGE extension. sit down, hydrate, let's get into it π§
β¨ NAME β¨
X11::Protocol::Ext::DAMAGE β drawing notifications π¦
πΈ SYNOPSIS πΈ
use X11::Protocol;
my $X = X11::Protocol->new;
$X->init_extension('DAMAGE')
or print "DAMAGE extension not available";
my $damage = $X->new_rsrc;
$X->DamageCreate ($damage, $drawable, 'NonEmpty');
sub my_event_handler {
my %h = @_;
if ($h{'name'} eq 'DamageNotify') {
my $drawable = $h{'drawable'};
$X->DamageSubtract ($damage, 'None', $parts_region);
# do something for $parts_region changed in $drawable
}
}
π DESCRIPTION π
The DAMAGE extension lets a client listen for changes to drawables β windows, pixmaps, etc β caused by drawing operations. And yes, that includes drawing into sub-windows that shows up in the parent. it's giving full coverage β¨
So what's it for? Efficient copying or replicating of window contents, no cap. Cloning to another screen? Magnified view? All of that π₯ You can even monitor the root window to catch changes across the entire screen. main character energy fr.
Content changes from drawing get conceived as "damage" π A server-side damage object accumulates areas as rectangles, building a server-side "region" following the XFIXES 2.0 extension (peep X11::Protocol::Ext::XFIXES).
A DamageNotify event gets sent from a damage object. There's a reporting level that controls how much detail you get β ranging from literally just one event when it becomes non-empty, all the way up to an event for every single drawing operation affecting the relevant drawable.
Fetching an accumulated damage region (or a part of it) counts as a "repair" π«Ά It doesn't change any drawables in any way, it just fetches the region from the damage object. And this fetch is atomic, so nothing gets lost if the listening client is a bit lagged etc. slay.
Check out examples/damage-duplicate.pl for one way to use damage to duplicate a window in real-time π
π οΈ REQUESTS π οΈ
These requests become available with an "init_extension()", as per "EXTENSIONS" in X11::Protocol.
my $is_available = $X->init_extension('DAMAGE');
π DAMAGE 1.0 π
($server_major, $server_minor) = $X->DamageQueryVersion ($client_major, $client_minor)β negotiate a protocol version with the server.$client_majorand$client_minoris what the client would like, and the returned$server_majorand$server_minoris what the server will actually do β which might be less than requested (but never more, bestie, never more).
The current code supports up to 1.1. If you're asking for higher then be careful that it's upwardly compatible. The module code negotiates a version inside "init_extension()", so an explicit "DamageQueryVersion()" is normally not needed π
$X->DamageCreate ($damage, $drawable, $level)β create a new damage object in$damage(a new XID) which monitors changes to$drawable. If$drawableis a window then changes to its subwindows are included too π
# listening to every change on the whole screen
my $damage = $X->new_rsrc;
$X->DamageCreate ($damage, $X->root, 'RawRectangles');
$level is an enum string controlling how often "DamageNotify" events are emitted (see "EVENTS" below).
RawRectangles every change
DeltaRectangles when damage region expands
BoundingBox when damage bounding box expands
NonEmpty when damage first becomes non-empty
$X->DamageDestroy ($damage)β destroy$damage. bye bestie π¦$X->DamageSubtract ($damage, $repair_region, $parts_region)β move the accumulated region in$damageover to$parts_region(a region XID), and clear it from$damage.
If $parts_region is "None" then $damage is cleared and the region discarded. Handy if, for example, the entire $drawable will be copied or re-examined, so the exact parts aren't needed. periodt.
$repair_region is what portion of $damage to consider. "None" means move and clear everything in $damage. Otherwise $repair_region is a region XID and the portion of the damage region within $repair_region is moved and cleared β anything outside is left sitting in $damage.
If anything is left in $damage then a new "DamageNotify" event is immediately sent π This can be good for instance if you picked out a $repair_region corresponding to what you thought was the window size (perhaps from the "geometry" field of a "DamageNotify" event), but it has grown in the interim. it's giving plot twist.
Region objects here can be created with the XFIXES 2.0 extension (see X11::Protocol::Ext::XFIXES). It should be available whenever DAMAGE is available. If you're using "None" and "None" to clear and discard then region objects aren't required and there's no need for an "init_extension('XFIXES')" π
π DAMAGE 1.1 π
$X->DamageAdd ($drawable, $region)β report to any interested damage objects that changes have occurred in$region(a region XID) of$drawable.
This one's used by clients which modify a drawable in ways the normal protocol drawing operations don't see π For example an MIT-SHM shared memory pixmap modified by writing to the memory (see X11::Protocol::Ext::MIT_SHM), or the various "direct rendering" to graphics hardware or GL etc. sneaky but valid β¨
π¦ EVENTS π¦
"DamageNotify" events are sent to the client which created the damage object. These events are always generated β there's nothing to select or deselect them. The event has the usual fields:
name "DamageNotify"
synthetic true if from a SendEvent
code integer opcode
sequence_number integer
and event-specific fields:
damage XID, damage object
drawable XID, as from DamageCreate
level enum, as from DamageCreate
more boolean, if more DamageNotify on the way
time integer, server timestamp
area arrayref [$x,$y,$width,$height]
geometry arrayref [$rootx,$rooty,$width,$height]
"drawable" and "level" are as from the "DamageCreate()" which made the "damage" object.
"more" is true if there's further "DamageNotify" events on the way for this damage object. This can happen when the "level" means there's a set of "area" rectangles to report.
"area" is a rectangle within "drawable", as a 4-element arrayref,
[ $x, $y, $width, $height ]
What it covers depends on the reporting level you requested π
"RawRectangles"β a rectangle around an arc, line, etc, drawing operation which changed"drawable"."DeltaRectangles"β an additional rectangle extending the damage region. Only new rectangles are reported, not any of the existing damage region. Reporting a region addition may require multiple"DamageNotify"events."BoundingBox"β a bounding box around the damage region accumulated, bigger than previously reported."NonEmpty"β umm, something, maybe the entire drawable. π (yeah that's literally what the docs say, i'm not gonna pretend otherwise)
"geometry" is the current size and position of the drawable as a 4-element arrayref in root window coordinates. For a pixmap $root_x and $root_y are 0.
[ $root_x, $root_y, $width, $height ]
π ENUM TYPES π
That reporting level above is type DamageReportLevel. So for example (after a successful "$X->init_extension('DAMAGE')"),
$number = $X->num('DamageReportLevel', 'RawRectangles');
$string = $X->interp('DamageReportLevel', 3);
See "SYMBOLIC CONSTANTS" in X11::Protocol. iykyk π§
π ERRORS π
Error type Damage is a bad $damage resource XID in a request.
π BUGS π
The server extension version number is queried in the "init_extension()", but not yet made available as such. The version determines whether "DamageAdd()" ought to work. Currently that request is always setup, but presumably generates an Opcode error if the server doesn't have it. not me being honest about it π
β SEE ALSO β
X11::Protocol, X11::Protocol::Ext::XFIXES
/usr/share/doc/x11proto-damage-dev/damageproto.txt.gz, <http://cgit.freedesktop.org/xorg/proto/damageproto/tree/damageproto.txt>
πΈ HOME PAGE πΈ
<http://user42.tuxfamily.org/x11-protocol-other/index.html>
π LICENSE π
okay legal moment bestie, putting on my serious face π«Ά
Copyright 2011, 2012, 2013, 2014, 2017 Kevin Ryde
X11-Protocol-Other is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
X11-Protocol-Other is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
and that's the whole page, bestie π this was perl v5.28.1, dated 2019-08-26, and the footer was serving X11::P...DAMAGE(3pm) energy the whole time. go forth and monitor your drawables, you absolute icon πβ¨
π¦ where this page comes from
- debian bookworm: libx11-protocol-other-perl 31-1 Β· GPL-3.0-or-later
- debian trixie: libx11-protocol-other-perl 31-1 Β· GPL-3.0-or-later
- ubuntu jammy: libx11-protocol-other-perl 31-1 Β· GPL-3.0-or-later
- ubuntu noble: libx11-protocol-other-perl 31-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms