| 1 | |||
| 2 | # The X Rotate and Resolution Extension Protocol | ||
| 3 | package X11::Protocol::Ext::RANDR; | ||
| 4 | |||
| 5 | use X11::Protocol qw(pad padding make_num_hash); | ||
| 6 | use X11::Protocol::Enhanced; | ||
| 7 | use Carp; | ||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | use vars '$VERSION'; | ||
| 11 | $VERSION = 0.01; | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | X11::Protocol::Ext::RANDR -- Perl extension module for the X Resize, Rotate and Reflect Extension | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | use X11::Protocol; | ||
| 20 | $x = X11::Protocol->new($ENV{'DISPLAY'}); | ||
| 21 | $x->init_extension('RANDR') or die; | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | This moudle is used by the L<X11::Protocol(3pm)> module to participate | ||
| 26 | in the resize, rotate and reflect extension to the X protocol, allowing | ||
| 27 | a client to participate or control these screen changes per L<The X | ||
| 28 | Resize, Rotate and Reflect Extension>, a copy of which can be obtained | ||
| 29 | from L<http://www.x.org/releases/X11R7.7/doc/randrproto/randrproto.txt>. | ||
| 30 | |||
| 31 | This manual page does not attempt to document the protocol itself, see | ||
| 32 | the specification for that. It documents the L</CONSTANTS>, | ||
| 33 | L</REQUESTS>, L</EVENTS> and L</ERRORS> that are added to the | ||
| 34 | L<X11::Protocol(3pm)> module. | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | sub new | ||
| 39 | { | ||
| 40 | my $self = bless {}, shift; | ||
| 41 | my ($x, $request_base, $event_base, $error_base) = @_; | ||
| 42 | |||
| 43 | =head1 CONSTANTS | ||
| 44 | |||
| 45 | B<X11::Protocol::Ext::RANDR> provides the following symbolic constants: | ||
| 46 | |||
| 47 | Rotation => | ||
| 48 | [ qw(Rotate_0 Rotate_90 Rotate_180 Rotate_270 | ||
| 49 | Reflect_X Refect_Y) ] | ||
| 50 | |||
| 51 | RRSelectMask => | ||
| 52 | [ qw(ScreenChangeNotifyMask CrtcChangeNotifyMask | ||
| 53 | OutputChangeNotifyMask OutputPropertyNotifyMask) ] | ||
| 54 | |||
| 55 | RRConfigStatus => | ||
| 56 | [ qw(Success InvalidConfigTime InvalidTime Failed) ] | ||
| 57 | |||
| 58 | ModeFlag => | ||
| 59 | [ qw(HSyncPositive HSyncNegative VSyncPositive VSyncNegative | ||
| 60 | Interlace DoubleScan CSync CSyncPositive CSyncNegative | ||
| 61 | HSkewPercent BCast PixelMultiplex | ||
| 62 | DoubleClock ClockDividedBy2) ] | ||
| 63 | |||
| 64 | Connection => | ||
| 65 | [ qw(Connected Disconnected UnknownConnection) ] | ||
| 66 | |||
| 67 | SubpixelOrder => | ||
| 68 | [ qw(Unknown HoizontalRGB HorizontalBGR VerticalRGB VerticalBGR | ||
| 69 | None) ] | ||
| 70 | |||
| 71 | =cut | ||
| 72 | $x->{ext_const}{Rotation} = | ||
| 73 | [ qw(Rotate_0 Rotate_90 Rotate_180 Rotate_270 Reflect_X | ||
| 74 | Refect_Y) ]; | ||
| 75 | $x->{ext_const}{RRSelectMask} = | ||
| 76 | [ qw(ScreenChangeNotifyMask CrtcChangeNotifyMask | ||
| 77 | OutputChangeNotifyMask OutputPropertyNotifyMask) ]; | ||
| 78 | $x->{ext_const}{RRConfigStatus} = | ||
| 79 | [ qw(Success InvalidConfigTime InvalidTime Failed) ]; | ||
| 80 | $x->{ext_const}{ModeFlag} = | ||
| 81 | [ qw(HSyncPositive HSyncNegative VSyncPositive VSyncNegative | ||
| 82 | Interlace DoubleScan CSync CSyncPositive CSyncNegative | ||
| 83 | HSkewPercent BCast PixelMultiplex | ||
| 84 | DoubleClock ClockDividedBy2) ]; | ||
| 85 | $x->{ext_const}{Connection} = | ||
| 86 | [ qw(Connected Disconnected UnknownConnection) ]; | ||
| 87 | $x->{ext_const}{SubpixelOrder} = | ||
| 88 | [ qw(Unknown HorizontalRGB HorizontalBGR VerticalRGB VerticalBGR | ||
| 89 | None) ]; | ||
| 90 | $x->{ext_const}{Mode} = [ qw(None) ]; | ||
| 91 | |||
| 92 | $x->{ext_const_num}{$_} = {make_num_hash($x->{ext_const}{$_})} | ||
| 93 | foreach (qw(Rotation RRSelectMask RRConfigStatus ModeFlag | ||
| 94 | Connection SubpixelOrder Mode)); | ||
| 95 | |||
| 96 | =head1 ERRORS | ||
| 97 | |||
| 98 | B<X11::Protocol::Ext::RANDR> provides the folowing bad resource errors: | ||
| 99 | C<Output>, C<Crtc>, C<Mode>. | ||
| 100 | |||
| 101 | =cut | ||
| 102 | { | ||
| 103 | my $i = $error_base; | ||
| 104 | foreach (qw(Output Crtc Mode)) { | ||
| 105 | $x->{ext_const}{Error}[$i] = $_; | ||
| 106 | $x->{ext_const_num}{Error}{$_} = $i; | ||
| 107 | $x->{ext_error_type}[$i] = 1; # bad resource | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | =head1 REQUESTS | ||
| 112 | |||
| 113 | B<X11::Protocol::Ext::RANDR> provides the following requests: | ||
| 114 | |||
| 115 | =cut | ||
| 116 | |||
| 117 | =pod | ||
| 118 | |||
| 119 | $X->RRQueryVersion($major, $minor) | ||
| 120 | => | ||
| 121 | ($major, $minor) | ||
| 122 | =cut | ||
| 123 | $x->{ext_request}{$request_base}[0] = [RRQueryVersion=>sub{ | ||
| 124 | return pack('LL',@_[1..2]); | ||
| 125 | },sub{ | ||
| 126 | return unpack('xxxxxxxxCC', $_[1]); | ||
| 127 | }]; | ||
| 128 | =pod | ||
| 129 | |||
| 130 | $X->RRSetScreenConfig($window, $time, $config_time, size_index, | ||
| 131 | rotation_reflection, refresh_rate) | ||
| 132 | => | ||
| 133 | ($status, $time, $config_time, $root, $subpixel_order) | ||
| 134 | =cut | ||
| 135 | $x->{ext_request}{$request_base}[2] = [RRSetScreenConfig=>sub{ | ||
| 136 | return pack('LLLSSSxx', @_[1..6]); | ||
| 137 | },sub{ | ||
| 138 | return unpack('xCxxxxxxLLLSx[10]', $_[1]); | ||
| 139 | }]; | ||
| 140 | =pod | ||
| 141 | |||
| 142 | $X->RRSelectInput($window, $enable) | ||
| 143 | |||
| 144 | $enable => $RRSelectMask # mask | ||
| 145 | =cut | ||
| 146 | $x->{ext_request}{$request_base}[4] = [RRSelectInput=>sub{ | ||
| 147 | my ($x,@vals) = @_; | ||
| 148 | $vals[1] = $x->pack_mask(RRSelectMask=>$vals[1]); | ||
| 149 | return pack('LSxx',@vals); | ||
| 150 | }]; | ||
| 151 | =pod | ||
| 152 | |||
| 153 | $X->RRGetScreenInfo($window) | ||
| 154 | => | ||
| 155 | ($rotations, $root, $time, $config_time, $size_index, | ||
| 156 | $rotation_and_reflection, $rate, $screensizes, $rateinfos) | ||
| 157 | |||
| 158 | $screensizes => [ $screensize, ... ] | ||
| 159 | $screensize => [ $width, $height, $width_mm, $height_mm ] | ||
| 160 | |||
| 161 | $rateinfos => [ $rateinfos, ... ] | ||
| 162 | $rateinfo => [ $rate, ... ] | ||
| 163 | =cut | ||
| 164 | $x->{ext_request}{$request_base}[5] = [RRGetScreenInfo=>sub{ | ||
| 165 | return pack('L',$_[1]); | ||
| 166 | },sub{ | ||
| 167 | my ($x,$data) = @_; | ||
| 168 | my $off = 0; | ||
| 169 | my ($nscreensize,$lrateinfo) = | ||
| 170 | unpack('x[20]Sx[6]Sxx', substr($data,$off,32)); | ||
| 171 | my @vals = | ||
| 172 | unpack('xCxxxxxxLLLxxSSSxxxx', substr($data,$off,32)); | ||
| 173 | $off += 32; | ||
| 174 | my $screensizes = []; | ||
| 175 | push @vals, $screensizes; | ||
| 176 | for (my $i=0;$i<$nscreensize;$i++) { | ||
| 177 | push @$screensizes, | ||
| 178 | [unpack('SSSS',substr($data,$off,8))]; | ||
| 179 | $off += 8; | ||
| 180 | } | ||
| 181 | my $rateinfos = []; | ||
| 182 | push @vals, $rateinfos; | ||
| 183 | $lrateinfo <<= 1; | ||
| 184 | while ($lrateinfo > 0) { | ||
| 185 | my $num = unpack('S',substr($data,$off,2)); | ||
| 186 | my $tot = 2+2*$num; | ||
| 187 | push @$rateinfos, | ||
| 188 | [unpack('xxS*', substr($data,$off,$tot))]; | ||
| 189 | $off += $tot; | ||
| 190 | $lrateinfo -= $tot; | ||
| 191 | } | ||
| 192 | return @vals; | ||
| 193 | }]; | ||
| 194 | =pod | ||
| 195 | |||
| 196 | $X->RRGetScreenSizeRange($window) | ||
| 197 | => | ||
| 198 | ($minWidth, $minHeight, $maxWidth, $maxHeight) | ||
| 199 | =cut | ||
| 200 | $x->{ext_request}{$request_base}[6] = [RRGetScreenSizeRange=>sub{ | ||
| 201 | return pack('L',$_[1]); | ||
| 202 | },sub{ | ||
| 203 | return unpack('x8SSSSx16', $_[1]); | ||
| 204 | }]; | ||
| 205 | =pod | ||
| 206 | |||
| 207 | $X->RRSetScreenSize($window, $width, $height, $width_mm, $height_mm) | ||
| 208 | =cut | ||
| 209 | $x->{ext_request}{$request_base}[7] = [RRSetScreenSize=>sub{ | ||
| 210 | return pack('LSSLL', @_[1..5]); | ||
| 211 | }]; | ||
| 212 | =pod | ||
| 213 | |||
| 214 | $X->RRGetScreenResources($window) | ||
| 215 | => | ||
| 216 | ($time, $config_time, $crtcs, $outputs, $modeinfos) | ||
| 217 | |||
| 218 | $crtcs => [ $crtc, ... ] | ||
| 219 | $outputs => [ $output, ... ] | ||
| 220 | $modeinfos => [ $modeinfo, ... ] | ||
| 221 | |||
| 222 | $modeinfo => [ $id, $width, $heigth, $dot_clock, $h_sync_start, | ||
| 223 | $h_sync_end, $h_total, $h_skew, $v_sync_start, | ||
| 224 | $v_sync_end, $v_total, $mode_flags, $name ] | ||
| 225 | |||
| 226 | $mode_flags => $ModeFlag # mask | ||
| 227 | =cut | ||
| 228 | $x->{ext_request}{$request_base}[8] = [RRGetScreenResources=>sub{ | ||
| 229 | return pack('L',$_[1]); | ||
| 230 | },sub{ | ||
| 231 | my ($x,$data) = @_; | ||
| 232 | my $off = 0; | ||
| 233 | my @vals = unpack('x8LLSSSx10',$data); | ||
| 234 | $off += 32; | ||
| 235 | my ($c,$o,$m) = (@vals[2..4]); | ||
| 236 | $vals[2] = [unpack('L*',substr($data,$off,$c<<4))]; | ||
| 237 | $off += $c<<4; | ||
| 238 | $vals[3] = [unpack('L*',substr($data,$off,$o<<4))]; | ||
| 239 | $off += $o<<4; | ||
| 240 | my $modeinfos = $vals[4] = []; | ||
| 241 | for (my $i=0;$i<$m;$i++) { | ||
| 242 | my @modeinfo = | ||
| 243 | (unpack('LSSLSSSSSSSSL',substr($data,$off,32))); | ||
| 244 | $off += 32; | ||
| 245 | @modeinfo = (@modeinfo[0..10],$modeinfo[12],$modeinfo[11]); | ||
| 246 | push @$modeinfos, \@modeinfo; | ||
| 247 | } | ||
| 248 | foreach (@$modeinfos) { | ||
| 249 | my $len = $_->[-1]; | ||
| 250 | $_->[-1] = substr($data,$off,$len); | ||
| 251 | $off += $len; | ||
| 252 | } | ||
| 253 | return @vals; | ||
| 254 | }]; | ||
| 255 | =pod | ||
| 256 | |||
| 257 | $X->RRGetOutputInfo($output, $config_time) | ||
| 258 | => | ||
| 259 | ($status, $time, $crtc, $width_mm, $height_mm, $connection, | ||
| 260 | $subpixel_order, $preferred_modes, $crtcs, $modes, $clones, $name) | ||
| 261 | =cut | ||
| 262 | $x->{ext_request}{$request_base}[9] = [RRGetOutputInfo=>sub{ | ||
| 263 | my ($x,@vals) = @_; | ||
| 264 | $vals[0] = $x->num(Output=>$vals[0]); | ||
| 265 | return pack('LL',@vals); | ||
| 266 | },sub{ | ||
| 267 | my ($x,$data) = @_; | ||
| 268 | my $off = 0; | ||
| 269 | my ($ncrtcs,$nmodes,$nclones,$lname) = | ||
| 270 | unpack('x[26]SSxxSS',substr($data,$off,34)); | ||
| 271 | my @vals = unpack('xCxxxxxxLLLLCCxxxxSxxxx',substr($data,$off,36)); | ||
| 272 | $vals[0] = $x->interp(RRConfigStatus=>$vals[0]); | ||
| 273 | $vals[5] = $x->interp(Connection=>$vals[5]); | ||
| 274 | $vals[6] = $x->interp(SubpixelOrder=>$vals[6]); | ||
| 275 | $off += 36; | ||
| 276 | push @vals, [unpack('L*',substr($data,$off,$ncrtcs<<2))]; | ||
| 277 | $off += $ncrtcs<<2; | ||
| 278 | push @vals, [unpack('L*',substr($data,$off,$nmodes<<2))]; | ||
| 279 | $off += $nmodes<<2; | ||
| 280 | push @vals, [unpack('L*',substr($data,$off,$nclones<<2))]; | ||
| 281 | $off += $nclones<<2; | ||
| 282 | push @vals, substr($data,$off,$lname); | ||
| 283 | return @vals; | ||
| 284 | }]; | ||
| 285 | =pod | ||
| 286 | |||
| 287 | $X->RRListOutputProperties($output) | ||
| 288 | => | ||
| 289 | ($atom, ...) | ||
| 290 | =cut | ||
| 291 | $x->{ext_request}{$request_base}[10] = [RRListOutputProperties=>sub{ | ||
| 292 | return pack('L',$_[1]); | ||
| 293 | },sub{ | ||
| 294 | return unpack('L*',substr($_[1],32)); | ||
| 295 | }]; | ||
| 296 | =pod | ||
| 297 | |||
| 298 | $X->RRQueryOutputProperty($output,$atom) | ||
| 299 | => | ||
| 300 | ($pending, $range, $immutable, @values) | ||
| 301 | =cut | ||
| 302 | $x->{ext_request}{$request_base}[11] = [RRQueryOutputProperty=>sub{ | ||
| 303 | return pack('LL',@_[1..2]); | ||
| 304 | },sub{ | ||
| 305 | my ($x,$data) = @_; | ||
| 306 | my @vals = unpack('xxxxxxxxCCCx[21]L*',$data); | ||
| 307 | $vals[0] = $x->interp(Bool=>$vals[0]); | ||
| 308 | $vals[1] = $x->interp(Bool=>$vals[1]); | ||
| 309 | $vals[2] = $x->interp(Bool=>$vals[2]); | ||
| 310 | return @vals; | ||
| 311 | }]; | ||
| 312 | =pod | ||
| 313 | |||
| 314 | $X->RRConfigureOutputProperty($output,$atom,$pending,$range,@values) | ||
| 315 | =cut | ||
| 316 | $x->{ext_request}{$request_base}[12] = [RRConfigureOutputProperty=>sub{ | ||
| 317 | my ($x,@vals) = @_; | ||
| 318 | $vals[2] = $x->num(Bool=>$vals[2]); | ||
| 319 | $vals[3] = $x->num(Bool=>$vals[3]); | ||
| 320 | return pack('xxxxLLCCxxL*',@vals); | ||
| 321 | }]; | ||
| 322 | =pod | ||
| 323 | |||
| 324 | $X->RRChangeOutputProperty($output,$property,$type,$format,$mode,@values) | ||
| 325 | =cut | ||
| 326 | $x->{ext_request}{$request_base}[13] = [RRChangeOutputProperty=>sub{ | ||
| 327 | my ($x,$output,$property,$type,$format,$mode,@vals) = @_; | ||
| 328 | $mode = $x->num(ChangePropertyMode=>$mode); | ||
| 329 | my $list = ''; | ||
| 330 | $list = 'C*' if $format == 8; | ||
| 331 | $list = 'S*' if $format == 16; | ||
| 332 | $list = 'L*' if $format == 32; | ||
| 333 | my $data = pack('xxxxLLLCCxxL'.$list, | ||
| 334 | $output,$property,$type,$format,$mode, | ||
| 335 | scalar(@vals), @vals); | ||
| 336 | $data .= "\0" x ((-length($data))&3); | ||
| 337 | return $data; | ||
| 338 | }]; | ||
| 339 | =pod | ||
| 340 | |||
| 341 | $X->RRDeleteOutputProperty($output, $atom) | ||
| 342 | =cut | ||
| 343 | $x->{ext_request}{$request_base}[14] = [RRDeleteOutputProperty=>sub{ | ||
| 344 | return pack('LL',@_[1..2]); | ||
| 345 | }]; | ||
| 346 | =pod | ||
| 347 | |||
| 348 | $X->RRGetOutputProperty($output, $property, $type, $offset, $length, | ||
| 349 | $delete, $pending) | ||
| 350 | => | ||
| 351 | ($format, $type, $bytes_after, @values | ||
| 352 | =cut | ||
| 353 | $x->{ext_request}{$request_base}[15] = [RRGetOutputProperty=>sub{ | ||
| 354 | my ($x,@vars) = @_; | ||
| 355 | $vars[2] = 0 if $vars[2] eq 'AnyPropertyType'; | ||
| 356 | $vars[5] = $x->num(Bool=>$vars[5]); | ||
| 357 | $vars[6] = $x->num(Bool=>$vars[6]); | ||
| 358 | return pack('xxxxLLLLLCCxx',@vars); | ||
| 359 | },sub{ | ||
| 360 | my ($x,$data) = @_; | ||
| 361 | my @vars = unpack('xCx6LLx16', $data); | ||
| 362 | $vars[1] = 'None' unless $vars[1]; | ||
| 363 | if ($vars[0] == 8) { | ||
| 364 | push @vars, unpack('C*',substr($data,32)); | ||
| 365 | } | ||
| 366 | elsif ($vars[0] == 16) { | ||
| 367 | push @vars, unpack('S*',substr($data,32)); | ||
| 368 | } | ||
| 369 | elsif ($vars[0] == 32) { | ||
| 370 | push @vars, unpack('L*',substr($data,32)); | ||
| 371 | } | ||
| 372 | return @vars; | ||
| 373 | }]; | ||
| 374 | =pod | ||
| 375 | |||
| 376 | $X->RRCreateMode($window, $id, $width, $height, $dot_clock, | ||
| 377 | $h_sync_start, $h_sync_end, $h_total, $h_skew, $v_sync_start, | ||
| 378 | $v_sync_end, $v_total, $flags, $name) | ||
| 379 | => | ||
| 380 | ($mode) | ||
| 381 | |||
| 382 | =cut | ||
| 383 | $x->{ext_request}{$request_base}[16] = [RRCreateMode=>sub{ | ||
| 384 | my ($x,@vars) = @_; | ||
| 385 | $vars[12] = $x->pack_hash(ModeFlag=>$vars[12]); | ||
| 386 | return pack('LLSSLSSSSSSSSL', | ||
| 387 | @vars[0..11],length($vars[12])) . | ||
| 388 | $vars[12] ."\0" x ((-length($vars[12]))&3); | ||
| 389 | },sub{ | ||
| 390 | my ($x,$data) = @_; | ||
| 391 | my @vars = unpack('x8Lx20',$data); | ||
| 392 | $vars[0] = 'None' if $x->{interp} and $vars[0] == 0; | ||
| 393 | return (@vars); | ||
| 394 | }]; | ||
| 395 | =pod | ||
| 396 | |||
| 397 | $X->RRDestroyMode($mode) | ||
| 398 | =cut | ||
| 399 | $x->{ext_request}{$request_base}[17] = [RRDestroyMode=>sub{ | ||
| 400 | my ($x,$mode) = @_; | ||
| 401 | $mode = 0 if $mode eq 'None'; | ||
| 402 | return pack('L',$mode); | ||
| 403 | }]; | ||
| 404 | =pod | ||
| 405 | |||
| 406 | $X->RRAddOutputMode($output, $mode) | ||
| 407 | =cut | ||
| 408 | $x->{ext_request}{$request_base}[18] = [RRAddOutputMode=>sub{ | ||
| 409 | my ($x,$output,$mode) = @_; | ||
| 410 | $mode = 0 if $mode eq 'None'; | ||
| 411 | return pack('LL',$output,$mode); | ||
| 412 | }]; | ||
| 413 | =pod | ||
| 414 | |||
| 415 | $X->RRDeleteOutputMode($output, $mode) | ||
| 416 | =cut | ||
| 417 | $x->{ext_request}{$request_base}[19] = [RRDeleteOutputMode=>sub{ | ||
| 418 | my ($x,$output,$mode) = @_; | ||
| 419 | $mode = 0 if $mode eq 'None'; | ||
| 420 | return pack('LL',$output,$mode); | ||
| 421 | }]; | ||
| 422 | =pod | ||
| 423 | |||
| 424 | $X->RRGetCrtcInfo($ctrc,$config_time) | ||
| 425 | => | ||
| 426 | ($status, $timestamp, $x, $y, $width, $height, $mode, $current_randr, | ||
| 427 | $possible_rotations, $outputs, $possible_outputs) | ||
| 428 | |||
| 429 | $outputs => [ $output, ... ] | ||
| 430 | $possible_outputs => [ $output, ... ] | ||
| 431 | =cut | ||
| 432 | $x->{ext_request}{$request_base}[20] = [RRGetCrtcInfo=>sub{ | ||
| 433 | return pack('LL',@_[1..2]); | ||
| 434 | },sub{ | ||
| 435 | my ($x,$data) = @_; | ||
| 436 | my ($noutputs,$npossible) = | ||
| 437 | unpack('x28SS',$data); | ||
| 438 | my @vals = ( unpack('xCxxxxxxLssSSLxxxx',$data), | ||
| 439 | [unpack('L*',substr($data,28,$noutputs<<2))], | ||
| 440 | [unpack('L*',substr($data,28+($noutputs<<2),$npossible<<2))]); | ||
| 441 | return @vals; | ||
| 442 | }]; | ||
| 443 | =pod | ||
| 444 | |||
| 445 | $X->RRSetCrtcConfig($ctrc, $time, $config_time, $x, $y, $mode, $randr, | ||
| 446 | @outputs) | ||
| 447 | => | ||
| 448 | ($status, $new_time) | ||
| 449 | =cut | ||
| 450 | $x->{ext_request}{$request_base}[21] = [RRSetCrtcConfig=>sub{ | ||
| 451 | my ($x,@vals) = @_; | ||
| 452 | $vals[5] = 0 if $vals[5] eq 'None'; | ||
| 453 | $vals[6] = $x->num(Rotation=>$vals[6]); | ||
| 454 | return pack('xxxxLLLSSLSxxL*',@vals); | ||
| 455 | },sub{ | ||
| 456 | my ($x,$data) = @_; | ||
| 457 | my @vals = unpack('xCxxxxxxLx20',$data); | ||
| 458 | $vals[0] = $x->interp(RRConfigStatus=>$vals[0]); | ||
| 459 | return @vals; | ||
| 460 | }]; | ||
| 461 | =pod | ||
| 462 | |||
| 463 | $X->RRGetCrtcGammaSize($crtc) | ||
| 464 | => | ||
| 465 | ($size) | ||
| 466 | =cut | ||
| 467 | $x->{ext_request}{$request_base}[22] = [RRGetCrtcGammaSize=>sub{ | ||
| 468 | return pack('L',$_[1]); | ||
| 469 | },sub{ | ||
| 470 | return unpack('x8Sx22',$_[1]); | ||
| 471 | }]; | ||
| 472 | =pod | ||
| 473 | |||
| 474 | $X->RRGetCrtcGamma($crtc) | ||
| 475 | => | ||
| 476 | ($crtc, $reds, $greens, $blues) | ||
| 477 | =cut | ||
| 478 | $x->{ext_request}{$request_base}[23] = [RRGetCrtcGamma=>sub{ | ||
| 479 | return pack('L',$_[1]); | ||
| 480 | },sub{ | ||
| 481 | my $off = 0; | ||
| 482 | my @vals = unpack('x4LSxx',substr($_[1],$off,12)); | ||
| 483 | $off += 12; | ||
| 484 | my $n = $vals[1]; | ||
| 485 | push @vals, unpack("S$n",substr($_[1],$off,$n<<1)); | ||
| 486 | $off += $n<<1; | ||
| 487 | push @vals, unpack("S$n",substr($_[1],$off,$n<<1)); | ||
| 488 | $off += $n<<1; | ||
| 489 | push @vals, unpack("S$n",substr($_[1],$off,$n<<1)); | ||
| 490 | return @vals; | ||
| 491 | }]; | ||
| 492 | =pod | ||
| 493 | |||
| 494 | $X->RRSetCrtcGamma($crtc,@reds,@greens,@blues) | ||
| 495 | =cut | ||
| 496 | $x->{ext_request}{$request_base}[24] = [RRSetCrtcGamma=>sub{ | ||
| 497 | my ($x,$crtc,@rgbs) = @_; | ||
| 498 | my $n = @rgbs/3; | ||
| 499 | my $data = pack('xxxxLSxxS*',$crtc,$n,@rgbs); | ||
| 500 | $data .= "\0" x ((-length($data))&3); | ||
| 501 | return $data; | ||
| 502 | }]; | ||
| 503 | |||
| 504 | =pod | ||
| 505 | |||
| 506 | $X->RRGetScreenResourcesCurrent($window) | ||
| 507 | => | ||
| 508 | ($time, $config_time, $crtcs, $outputs, $modeinfos) | ||
| 509 | |||
| 510 | $crtcs => [ $crtc, ... ] | ||
| 511 | $outputs => [ $output, ... ] | ||
| 512 | $modeinfos => [ $modeinfo, ... ] | ||
| 513 | |||
| 514 | $modeinfo => [ $id, $width, $height, $dot_clock, $h_sync_start, | ||
| 515 | $h_sync_end, $h_total, $h_skew, $v_sync_start, | ||
| 516 | $v_sync_end, $v_total, $mod_flags, $name ] | ||
| 517 | $mode_flags => $ModeFlag # mask | ||
| 518 | =cut | ||
| 519 | $x->{ext_request}{$request_base}[25] = [RRGetScreenResourcesCurrent=>sub{ | ||
| 520 | return pack('L',$_[1]); | ||
| 521 | },sub{ | ||
| 522 | my ($x,$data) = @_; | ||
| 523 | my $off = 0; | ||
| 524 | my @vals = unpack('x8LLSSSx10',$data); | ||
| 525 | $off += 32; | ||
| 526 | my ($c,$o,$m) = (@vals[2..4]); | ||
| 527 | $vals[2] = [unpack('L*',substr($data,$off,$c<<4))]; | ||
| 528 | $off += $c<<4; | ||
| 529 | $vals[3] = [unpack('L*',substr($data,$off,$o<<4))]; | ||
| 530 | $off += $o<<4; | ||
| 531 | my $modeinfos = $vals[4] = []; | ||
| 532 | for (my $i=0;$i<$m;$i++) { | ||
| 533 | my @modeinfo = | ||
| 534 | [unpack('LSSLSSSSSSSSL',substr($data,$off,32))]; | ||
| 535 | $off += 32; | ||
| 536 | @modeinfo = (@modeinfo[0..10],$modeinfo[12],$modeinfo[11]); | ||
| 537 | push @$modeinfos, \@modeinfo; | ||
| 538 | } | ||
| 539 | foreach (@$modeinfos) { | ||
| 540 | my $len = $_->[-1]; | ||
| 541 | $_->[-1] = substr($data,$off,$len); | ||
| 542 | $off += $len; | ||
| 543 | } | ||
| 544 | return @vals; | ||
| 545 | }]; | ||
| 546 | =pod | ||
| 547 | |||
| 548 | $X->RRSetCrtcTransform($ctrc,$transform,$filter,@params) | ||
| 549 | =cut | ||
| 550 | $x->{ext_request}{$request_base}[26] = [RRSetCrtcTransform=>sub{ | ||
| 551 | my ($x,$crtc,$transform,$filter,@params) = @_; | ||
| 552 | my $len = length($filter); | ||
| 553 | my $pad = pad($len); | ||
| 554 | return pack("L(a36)Sxx(a*)x${pad}L*", | ||
| 555 | $crtc,$transform,$len,$filter,@params); | ||
| 556 | }]; | ||
| 557 | |||
| 558 | =pod | ||
| 559 | |||
| 560 | $X->RRGetCrtcTransform($crtc) | ||
| 561 | => | ||
| 562 | ($pending, $has_transforms, $current, $pending_filter, $current_filter) | ||
| 563 | |||
| 564 | $pending_filter => [ $filter, @params ] | ||
| 565 | $current_filter => [ $filter, @params ] | ||
| 566 | =cut | ||
| 567 | $x->{ext_request}{$request_base}[27] = [RRGetCrtcTransform=>sub{ | ||
| 568 | return pack('L',$_[1]); | ||
| 569 | },sub{ | ||
| 570 | my ($x,$data) = @_; | ||
| 571 | my ($pn,$pf,$cn,$cf) = unpack('x88SSSS',$data); | ||
| 572 | my $pnp = padding($pn); | ||
| 573 | my $cnp = padding($cn); | ||
| 574 | my @vals = unpack('x8(a36)Cxxx(a36)x4',$data); | ||
| 575 | $vals[1] = $x->interp(Bool=>$vals[1]); | ||
| 576 | my $off = 96; | ||
| 577 | push @vals, | ||
| 578 | [unpack("(a${pn})x${pnp}L*",substr($data,$off,$pn+$pnp+($pf<<2)))]; | ||
| 579 | $off += $pn+$pnp+($pf<<2); | ||
| 580 | push @vals, | ||
| 581 | [unpack("(a${cn})x${cnp}L*",substr($data,$off,$cn+$cnp+($cf<<2)))]; | ||
| 582 | return @vals; | ||
| 583 | }]; | ||
| 584 | |||
| 585 | =pod | ||
| 586 | |||
| 587 | $X->RRGetPanning($crtc) | ||
| 588 | => | ||
| 589 | ($status, $time, $left, $top, $width, $height, $track_left, $track_top, | ||
| 590 | $track_width, $track_height, $border_left, $border_top, $border_right, | ||
| 591 | $border_bottom) | ||
| 592 | =cut | ||
| 593 | $x->{ext_request}{$request_base}[28] = [RRGetPanning=>sub{ | ||
| 594 | return pack('L',$_[1]); | ||
| 595 | },sub{ | ||
| 596 | my @vals = unpack('xCxxxxxxLSSSSSSSSssss',$_[1]); | ||
| 597 | $vals[0] = $x->interp(RRConfigStatus=>$vals[0]); | ||
| 598 | return @vals; | ||
| 599 | }]; | ||
| 600 | |||
| 601 | =pod | ||
| 602 | |||
| 603 | $X->RRSetPanning($crtc, $time, $left, $top, $width, $height, | ||
| 604 | $track_left, $track_top, $track_width, $track_height, | ||
| 605 | $border_left, $border_top, $border_right, $border_bottom) | ||
| 606 | => | ||
| 607 | ($status, $new_time) | ||
| 608 | =cut | ||
| 609 | $x->{ext_request}{$request_base}[29] = [RRSetPanning=>sub{ | ||
| 610 | return pack('LLSSSSSSSSssss',@_[1..14]); | ||
| 611 | },sub{ | ||
| 612 | my @vals = unpack('xCxxxxxxLx20',$_[1]); | ||
| 613 | $vals[0] = $x->interp(RRConfigStatus=>$vals[0]); | ||
| 614 | return @vals; | ||
| 615 | }]; | ||
| 616 | |||
| 617 | =pod | ||
| 618 | |||
| 619 | $X->RRSetOutputPrimary($window, $output) | ||
| 620 | =cut | ||
| 621 | $x->{ext_request}{$request_base}[30] = [RRSetOutputPrimary=>sub{ | ||
| 622 | return pack('LL',@_[1..2]); | ||
| 623 | }]; | ||
| 624 | |||
| 625 | =pod | ||
| 626 | |||
| 627 | $X->RRGetOutputPrimary($window) | ||
| 628 | => | ||
| 629 | ($length, $output, @pads) | ||
| 630 | =cut | ||
| 631 | $x->{ext_request}{$request_base}[31] = [RRGetOutputPrimary=>sub{ | ||
| 632 | return pack('L',$_[1]); | ||
| 633 | },sub{ | ||
| 634 | return unpack('xxxxL6',$_[1]); | ||
| 635 | }]; | ||
| 636 | |||
| 637 | =head1 EVENTS | ||
| 638 | |||
| 639 | B<X11::Protocol::Ext::RANDR> provides the following events: | ||
| 640 | |||
| 641 | The following events were added in Version 1.0 of the specification. | ||
| 642 | This event uses a single event number. | ||
| 643 | |||
| 644 | RRScreenChangeNotify => { | ||
| 645 | name=>'RRScreenChangeNotify', | ||
| 646 | new_rotation_and_reflection=>$rotation, # Rotation | ||
| 647 | timestamp=>$timestamp, | ||
| 648 | configuration_timestamp=>$timestamp, | ||
| 649 | root_window=>$window, | ||
| 650 | request_window=>$window, | ||
| 651 | size_id=>$sizeid, # SizeID | ||
| 652 | subpixel_order_defined_in_render=>$subpixelorder, | ||
| 653 | width_in_pixels=>$width, | ||
| 654 | height_in_pixels=>$height, | ||
| 655 | width_in_millimeters=>$width_mm, | ||
| 656 | height_in_millimeters=>$height_mm} | ||
| 657 | |||
| 658 | =cut | ||
| 659 | $x->{ext_const}{Events}[$event_base+0] = 'RRScreenChangeNotify'; | ||
| 660 | $x->{ext_events}[$event_base+0] = ['xCxxLLLLSSSSSS', | ||
| 661 | [timestamp=>['CurrentTime']], | ||
| 662 | [configuration_timestamp=>['CurrentTime']], qw(root_window | ||
| 663 | request_window), [size_id=>'SizeID'], | ||
| 664 | qw(subpixel_order_defined_in_render width_in_pixels | ||
| 665 | height_in_pixels width_in_millimeters heigth_in_millimeters)]; | ||
| 666 | =pod | ||
| 667 | |||
| 668 | The following events were added in Version 1.2 of the specification. | ||
| 669 | Unfortunately they chose to multiplex the events under only one | ||
| 670 | additional event number. Therefore, the format of these events depend | ||
| 671 | on the value of the C<sub_code> field which is of type | ||
| 672 | C<RR1dot2EventType>. | ||
| 673 | |||
| 674 | =cut | ||
| 675 | my $RR1dot2EventTypePack = []; | ||
| 676 | =pod | ||
| 677 | |||
| 678 | RRCrtcChangeNotify => { | ||
| 679 | name=>'RR1dot2EventNotify', | ||
| 680 | sub_code=>$RR1dot2EventType, # 0 or 'RRCrtcChangeNotify' | ||
| 681 | timestamp=>$timestamp, | ||
| 682 | request_window=>$window, | ||
| 683 | crtc_affected=>$crtc, | ||
| 684 | mode_in_use=>$mode, # Mode | ||
| 685 | new_rotation_and_reflection=>$rotation, # Rotation | ||
| 686 | x=>$x, | ||
| 687 | y=>$y, | ||
| 688 | width=>$width, | ||
| 689 | height=>$height} | ||
| 690 | |||
| 691 | =cut | ||
| 692 | $RR1dot2EventTypePack->[0] = | ||
| 693 | [ RRCrtcChangeNotify => sub{ | ||
| 694 | my ($x,$data,%ret) = @_; | ||
| 695 | my @vals = unpack('xCxxLLLLSxxSSSS', $data); | ||
| 696 | foreach (qw(sub_code timestamp request_window ctrc_affected | ||
| 697 | mode_in_use new_rotation_and_reflection x y | ||
| 698 | width height)) { | ||
| 699 | $ret{$_} = shift @vals; | ||
| 700 | } | ||
| 701 | $ret{sub_code} = $x->interp(RR1dot2EventType=>$ret{sub_code}); | ||
| 702 | return (%ret); | ||
| 703 | }, sub{ | ||
| 704 | my ($x,%h) = @_; | ||
| 705 | my $do_seq = 1; | ||
| 706 | $h{sub_code} = $x->num(RR1dot2EventType=>$h{sub_code}); | ||
| 707 | my @vals = (); | ||
| 708 | foreach (qw(sub_code timestamp request_window ctrc_affected | ||
| 709 | mode_in_use new_rotation_and_reflection x y | ||
| 710 | width height)) { | ||
| 711 | push @vals, $h{$_}; | ||
| 712 | } | ||
| 713 | my $data = pack('xCxxLLLLSxxSSSS', @vals); | ||
| 714 | return ($data, $do_seq); | ||
| 715 | }]; | ||
| 716 | =pod | ||
| 717 | |||
| 718 | RROutputChangeNotify => { | ||
| 719 | name=>'RR1dot2EventNotify', | ||
| 720 | sub_code=>$RR1dot2EventType, # 1 or 'RROutputChangeNotify | ||
| 721 | timestamp=>$time, | ||
| 722 | configuration_timestamp=>$config_time, | ||
| 723 | request_window=>$window, | ||
| 724 | output_affected=>$output, | ||
| 725 | crtc_in_use=>$crtc, | ||
| 726 | mode_in_use=>$mode, | ||
| 727 | rotation_in_use=>$rotation, # Rotation | ||
| 728 | connection_status=>$status, # Connection | ||
| 729 | subpixel_order=>$subpixel_order} | ||
| 730 | |||
| 731 | =cut | ||
| 732 | $RR1dot2EventTypePack->[1] = | ||
| 733 | [ RROutputChangeNotify => sub{ | ||
| 734 | my ($x,$data,%ret) = @_; | ||
| 735 | my @vals = unpack('xCxxLLLLLLSCC', $data); | ||
| 736 | foreach (qw(sub_code timestamp configuration_timestamp | ||
| 737 | request_window output_affected crtc_in_use | ||
| 738 | mode_in_use rotation_in_use connection_status | ||
| 739 | subpixel_order)) { | ||
| 740 | $ret{$_} = shift @vals; | ||
| 741 | } | ||
| 742 | $ret{sub_code} = $x->interp(RR1dot2EventType=>$ret{sub_code}); | ||
| 743 | return (%ret); | ||
| 744 | }, sub{ | ||
| 745 | my ($x,%h) = @_; | ||
| 746 | my $do_seq = 1; | ||
| 747 | $h{sub_code} = $x->num(RR1dot2EventType=>$h{sub_code}); | ||
| 748 | my @vals = (); | ||
| 749 | foreach (qw(sub_code timestamp configuration_timestamp | ||
| 750 | request_window output_affected crtc_in_use | ||
| 751 | mode_in_use rotation_in_use connection_status | ||
| 752 | subpixel_order)) { | ||
| 753 | push @vals, $h{$_}; | ||
| 754 | } | ||
| 755 | my $data = pack('xCxxLLLLLLSCC', @vals); | ||
| 756 | return ($data, $do_seq); | ||
| 757 | }]; | ||
| 758 | =pod | ||
| 759 | |||
| 760 | RROutputPropertyNotify => { | ||
| 761 | name=>'RR1dot2EventNotify', | ||
| 762 | sub_code=>$RR1dot2EventType, # 2 or 'RROutputPropertyNotify | ||
| 763 | window=>$window, | ||
| 764 | output=>$output, | ||
| 765 | atom=>$atom, | ||
| 766 | timestamp=>$time} | ||
| 767 | |||
| 768 | =cut | ||
| 769 | $RR1dot2EventTypePack->[2] = | ||
| 770 | [ RROutputPropertyNotify => sub{ | ||
| 771 | my ($x,$data,%ret) = @_; | ||
| 772 | my @vals = unpack('xCxxLLLLCx[11]', $data); | ||
| 773 | foreach (qw(sub_code window output atom time state)) { | ||
| 774 | $ret{$_} = shift @vals; | ||
| 775 | } | ||
| 776 | $ret{sub_code} = $x->interp(RR1dot2EventType=>$ret{sub_code}); | ||
| 777 | return (%ret); | ||
| 778 | }, sub{ | ||
| 779 | my ($x,%h) = @_; | ||
| 780 | my $do_seq = 1; | ||
| 781 | $h{sub_code} = $x->num(RR1dot2EventType=>$h{sub_code}); | ||
| 782 | my @vals = (); | ||
| 783 | foreach (qw(sub_code window output atom time state)) { | ||
| 784 | push @vals, $h{$_}; | ||
| 785 | } | ||
| 786 | my $data = pack('xCxxLLLLCx[11]', @vals); | ||
| 787 | return ($data, $do_seq); | ||
| 788 | }]; | ||
| 789 | |||
| 790 | |||
| 791 | $x->{ext_const}{Events}[$event_base+1] = 'RR1dot2EventNotify'; | ||
| 792 | $x->{ext_events}[$event_base+1] = [sub{ | ||
| 793 | my ($x,%ret); | ||
| 794 | }, sub{ | ||
| 795 | }]; | ||
| 796 | $x->{ext_const}{Events}[$event_base+1] = q(RRCrtcChangeNotify); | ||
| 797 | $x->{ext_events}[$event_base+1] = ['xxxxLLLLSxxSSSS', | ||
| 798 | [timestamp => ['CurrentTime']], 'request_window', | ||
| 799 | 'crtc_affected', [mode => ['None']], | ||
| 800 | [new_rotation_and_reflection => 'Rotation'], | ||
| 801 | 'x', 'y', 'width', 'height']; | ||
| 802 | $x->{ext_const}{Events}[$event_base+1] = q(RROutputChangeNotify); | ||
| 803 | $x->{ext_events}[$event_base+1] = ['xxxxLLLLLLSCC', | ||
| 804 | [timestamp=>['CurrentTime']], | ||
| 805 | [configuration_timestamp=>['CurrentTime']], | ||
| 806 | [request_window=>['None']], | ||
| 807 | 'output_affected', 'crtc_in_use', [mode => ['None']], | ||
| 808 | [rotation_in_use=>'Rotation'], | ||
| 809 | [connection_status=>'Connection'], 'subpixel_order']; | ||
| 810 | |||
| 811 | |||
| 812 | $x->{ext_const}{Events}[$event_base+1] = q(RROutputPropertyNotify); | ||
| 813 | } | ||
| 814 | |||
| 815 | 1; | ||
| 816 | |||
| 817 | __END__ |