X11::P...DAMAGE(3pm)

πŸ“¦
version 31 Β· 7 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸŽ€ 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_major and $client_minor is what the client would like, and the returned $server_major and $server_minor is 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 $drawable is 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 $damage over 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