forked from nanardon/X11-Xlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PerlXlib.c
1854 lines (1683 loc) · 103 KB
/
PerlXlib.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
#ifdef HAVE_XRENDER
#include <X11/extensions/Xrender.h>
#endif
#include "PerlXlib.h"
static MGVTBL PerlXlib_dpy_mg_vtbl;
static MGVTBL PerlXlib_dpy_innerptr_mg_vtbl;
extern Display * PerlXlib_get_magic_dpy(SV *sv, Bool not_null) {
MAGIC *mg= NULL;
if (sv_isobject(sv)) {
for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) {
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &PerlXlib_dpy_mg_vtbl) {
if (!mg->mg_ptr && not_null) break;
return (Display*) mg->mg_ptr;
}
}
}
if (not_null) {
if (SvTRUE(get_sv("X11::Xlib::_error_fatal_trapped", GV_ADD)))
croak("Cannot call further Xlib functions after fatal Xlib error");
if (mg) /* has magic, but NULL pointer */
croak("X11 connection was closed");
if (!sv_derived_from(sv, "X11::Xlib"))
croak("Invalid X11 connection; must be instance of X11::Xlib");
croak("Invalid X11 connection; missing 'magic' Display* reference");
}
return NULL;
}
extern SV * PerlXlib_set_magic_dpy(SV *sv, Display *dpy) {
MAGIC *mg= NULL;
Display *old_dpy= NULL;
SV **fp;
HV *cache;
if (!sv_isobject(sv))
croak("Can't add magic Display* to non-object");
/* Search for existing Magic that would hold this pointer */
for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) {
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &PerlXlib_dpy_mg_vtbl) {
old_dpy= (Display*) mg->mg_ptr;
mg->mg_ptr= (void*) dpy;
break;
}
}
/* If value remains unchanged, nothing to do */
if (dpy == old_dpy) return sv;
/* If magic doesn't exist, add it */
if (!mg)
sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, &PerlXlib_dpy_mg_vtbl, (const char *) dpy, 0);
cache= get_hv("X11::Xlib::_connections", GV_ADD);
/* Object might be cached under old dpy key. Remove the cache reference. */
if (old_dpy)
hv_delete(cache, (void*) &old_dpy, sizeof(old_dpy), G_DISCARD);
/* Cache a weak ref to this object keyed by the new Display* value */
if (dpy) {
fp= hv_fetch(cache, (void*) &dpy, sizeof(dpy), 1);
if (!fp) croak("failed to add item to hash (tied?)");
if (*fp && SvROK(*fp) && SvRV(*fp) != SvRV(sv))
warn("Replacing cached connection object for Display* 0x%p!", dpy);
/* New weak-ref to this object
* Docs warn that sv_setsv might de-allocate mortal sources, so inc ref count temporarily
*/
SvREFCNT_inc(sv);
if (!*fp) *fp= newSVsv(sv); else sv_setsv(*fp, sv);
sv_2mortal(sv);
sv_rvweaken(*fp);
}
return sv;
}
/* Converting a Display* to a \X11::Xlib is difficult because we want
* to re-use the existing object. We cache them in %X11::Xlib::_connections.
* This function returns a mortal strong-reference to an instance of X11::Xlib (or subclass)
*/
extern SV * PerlXlib_obj_for_display(Display *dpy, int create) {
SV **fp, *self;
if (!dpy) {
/* Translate NULL to undef */
return &PL_sv_undef;
}
else {
fp= hv_fetch(get_hv("X11::Xlib::_connections", GV_ADD), (void*) &dpy, sizeof(dpy), 0);
/* Return existing object if we have one for this Display* already */
if (fp && *fp && SvROK(*fp)) {
/* create strong-ref from weakref */
return sv_mortalcopy(*fp);
}
else if (create) {
/* Always create instance of X11::Xlib. X11::Xlib::Display can re-bless as needed. */
self= sv_2mortal(newRV_noinc((SV*) newHV()));
sv_bless(self, gv_stashpv("X11::Xlib", GV_ADD));
PerlXlib_set_magic_dpy(self, dpy); /* This also adds it to the _connections cache */
return self;
}
else {
return sv_2mortal(newSVuv(PTR2UV(dpy)));
}
}
}
extern void * PerlXlib_get_magic_dpy_innerptr(SV *sv, Bool not_null) {
MAGIC *mg= NULL;
if (sv_isobject(sv)) {
for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) {
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &PerlXlib_dpy_innerptr_mg_vtbl) {
if (!mg->mg_ptr && not_null) break;
return mg->mg_ptr;
}
}
}
if (not_null)
croak("Object lacks Xlib magic pointer");
return NULL;
}
extern SV * PerlXlib_set_magic_dpy_innerptr(SV *sv, void *innerptr) {
MAGIC *mg= NULL;
SV **fp;
HV *cache;
if (!sv_isobject(sv))
croak("Can't add magic Xlib pointer to non-object");
/* Search for existing Magic that would hold this pointer */
for (mg = SvMAGIC(SvRV(sv)); mg; mg = mg->mg_moremagic) {
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &PerlXlib_dpy_innerptr_mg_vtbl) {
mg->mg_ptr= innerptr;
return sv;
}
}
/* If magic doesn't exist, add it */
sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, &PerlXlib_dpy_innerptr_mg_vtbl, (const char *) innerptr, 0);
return sv;
}
extern SV * PerlXlib_get_displayobj_of_opaque(void *opaque) {
SV **elem= hv_fetch(get_hv("X11::Xlib::_display_attr", GV_ADD),
(void*)&opaque, sizeof(void*), 0);
return (elem && *elem && sv_isobject(*elem))? *elem : &PL_sv_undef;
}
extern void PerlXlib_set_displayobj_of_opaque(void *opaque, SV *dpy_sv) {
SV **elem;
if (dpy_sv && SvOK(dpy_sv)) {
elem= hv_fetch(get_hv("X11::Xlib::_display_attr", GV_ADD),
(void*)&opaque, sizeof(void*), 1);
if (!elem) croak("Can't write X11::Xlib::_display_attr");
if (*elem && SvROK(*elem)) {
if (SvRV(dpy_sv) == SvRV(*elem))
return; /* redundant. ignore it. */
croak("Can't modify display attribute once it is initialized");
}
if (!*elem) *elem= newSV(0);
sv_setsv(*elem, dpy_sv);
}
else {
hv_delete(get_hv("X11::Xlib::_display_attr", GV_ADD),
(void*)&opaque, sizeof(void*), G_DISCARD);
}
}
/* Most other opaque pointers related to a Display* connection need paired with
* the Display* they represent, and should hold a strong reference to the Display*
* else the user might still be holding one after the display is closed.
*/
extern SV * PerlXlib_obj_for_display_innerptr(Display *dpy, void *thing, const char *thing_class, int objsvtype, bool create) {
SV **elem= NULL, *ret= NULL, *dpy_obj= NULL;
HV *obj_cache= NULL;
if (!thing)
return &PL_sv_undef;
if (dpy) {
dpy_obj= PerlXlib_obj_for_display(dpy, 1);
/* record which display it came from, in a strong-ref global */
PerlXlib_set_displayobj_of_opaque(thing, dpy_obj);
} else {
dpy_obj= PerlXlib_get_displayobj_of_opaque(thing);
}
/* If we have the display object, check its cache to see if this thing
* already has a cached wrapper object. */
if (dpy_obj && SvOK(dpy_obj)) {
/* first get the cache hashref */
elem= hv_fetch((HV*)SvRV(dpy_obj), "_obj_cache", 10, 1);
if (!elem) croak("Can't create $display->{_obj_cache}");
if (*elem && SvROK(*elem) && SvTYPE(SvRV(*elem)) == SVt_PVHV)
obj_cache= (HV*) SvRV(*elem);
else {
obj_cache= newHV();
if (*elem) sv_setsv(*elem, sv_2mortal(newRV_noinc((SV*) obj_cache)));
else *elem= newRV_noinc((SV*) newHV());
}
/* then check the obj_cache for a match */
elem= hv_fetch(obj_cache, (void*) &thing, sizeof(thing), 1);
if (elem && *elem && SvOK(*elem))
return *elem;
}
/* No object, unless we're allowed to create one */
if (!create)
return &PL_sv_undef;
/* if no display was given, we don't have an object cache. */
if (obj_cache) {
if (!elem) croak("Can't write to $display->{obj_cache}");
if (!*elem) *elem= newSV(0);
}
/* Now, if obj_cache is not null, then we can assign to *elem. */
if (objsvtype == SVt_PVMG) {
ret= sv_setref_pv(sv_newmortal(), thing_class, thing);
}
else if (objsvtype == SVt_PVHV) {
ret= sv_2mortal(newRV_noinc((SV*) newHV()));
sv_bless(ret, gv_stashpv(thing_class, GV_ADD));
PerlXlib_set_magic_dpy_innerptr(ret, thing);
}
else if (objsvtype == SVt_PVAV) {
ret= sv_2mortal(newRV_noinc((SV*) newAV()));
sv_bless(ret, gv_stashpv(thing_class, GV_ADD));
PerlXlib_set_magic_dpy_innerptr(ret, thing);
}
else
croak("Unsupported svtype in PerlXlib_obj_for_display_innerptr");
/* store a weak reference in the object cache */
if (obj_cache) {
/* ret is mortal, and sv_setsv warns that mortals might get freed... so do this silly dance */
SvREFCNT_inc(ret);
sv_setsv(*elem, ret);
sv_rvweaken(*elem);
sv_2mortal(ret);
}
return ret;
}
extern void * PerlXlib_sv_to_display_innerptr(SV *sv, bool not_null) {
void *ptr;
if (sv && sv_isobject(sv)) {
if (SvTYPE(SvRV(sv)) < SVt_PVAV)
ptr= INT2PTR(void*, SvIV((SV*)SvRV(sv)));
else
ptr= PerlXlib_get_magic_dpy_innerptr(sv, not_null);
if (ptr) return ptr;
}
if (not_null)
croak("Not an Xlib opaque pointer");
return NULL;
}
extern Screen * PerlXlib_sv_to_screen(SV *sv, bool not_null) {
HV *hv;
SV **elem;
Display *dpy;
int screennum;
if (!sv || !SvROK(sv) || !SvTYPE(SvRV(sv)) == SVt_PVHV) {
if (not_null || (sv && SvOK(sv)))
croak("expected X11::Xlib::Screen object");
return NULL;
}
hv= (HV*) SvRV(sv);
elem= hv_fetch(hv, "display", 7, 0);
if (!elem || !*elem || !(dpy= PerlXlib_get_magic_dpy(*elem, 1)))
croak("missing $screen->{display}");
elem= hv_fetch(hv, "screen_number", 13, 0);
if (!elem || !*elem || !SvIOK(*elem))
croak("missing $screen->{screen_number}");
screennum= SvIV(*elem);
if (screennum >= ScreenCount(dpy) || screennum < 0)
croak("Screen number %d out of bounds for this display (0..%d)",
screennum, ScreenCount(dpy)-1);
return ScreenOfDisplay(dpy, screennum);
}
extern SV * PerlXlib_obj_for_screen(Screen *screen) {
Display *dpy;
SV *dpy_sv, *ret= NULL;
int i;
if (!screen)
return &PL_sv_undef;
dpy= DisplayOfScreen(screen);
/* There's actually no way to get the screen number from the pointer,
* other than subtraction on private pointers... so just iterate.
* There's probably only one anyway. */
for (i= 0; i < ScreenCount(dpy); i++) {
if (screen == ScreenOfDisplay(dpy, i)) {
/* Need a X11::Xlib::Display object */
dpy_sv= PerlXlib_obj_for_display(dpy, 1);
/* Then call $display->screen(i) method */
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
EXTEND(SP, 2);
PUSHs(sv_mortalcopy(dpy_sv));
PUSHs(sv_2mortal(newSViv(i)));
PUTBACK;
if (call_method("screen", G_SCALAR) != 1)
croak("stack assertion failed");
SPAGAIN;
ret= POPs;
SvREFCNT_inc(ret); /* make sure it lives a little longer */
PUTBACK;
FREETMPS;
LEAVE;
sv_2mortal(ret);
sv_2mortal(dpy_sv);
break;
}
}
if (!ret) croak("Corrupt Xlib screen/display structures!");
return ret;
}
/* Allow unsigned integer, or hashref with field ->{xid} */
XID PerlXlib_sv_to_xid(SV *sv) {
SV **xid_field;
if (SvUOK(sv) || SvIOK(sv))
return (XID) SvUV(sv);
if (!SvROK(sv) || !(SvTYPE(SvRV(sv)) == SVt_PVHV)
|| !(xid_field= hv_fetch((HV*)SvRV(sv), "xid", 3, 0))
|| !*xid_field || !(SvIOK(*xid_field) || SvUOK(*xid_field)))
croak("Invalid XID (Window, etc); must be an unsigned int, or an instance of X11::Xlib::XID");
return (XID) SvUV(*xid_field);
}
/* Inspect each of the perl data structures that are directly manipulated by XS.
* This is only for debugging.
*/
void PerlXlib_sanity_check_data_structures() {
HV *dpys, *obj_cache, *display_attr;
HE *dpy_he, *obj_he;
SV *dpy_sv, *obj_sv, **elem;
Display *dpy;
void *opaque;
dpys= get_hv("X11::Xlib::_connections", GV_ADD);
/*hv_assert(dpys);*/
display_attr= get_hv("X11::Xlib::_display_attr", GV_ADD);
/*hv_assert(display_attr);*/
/* for each display */
for (hv_iterinit(dpys); (dpy_he= hv_iternext(dpys)); ) {
dpy_sv= hv_iterval(dpys, dpy_he);
/* SV refcnt should be exactly 1, and should be weakref. Ref'd object should have >1 refcnt */
if (SvREFCNT(dpy_sv) != 1) croak("Refcnt of %_connections member is %d", SvREFCNT(dpy_sv));
if (!SvROK(dpy_sv) || !SvWEAKREF(dpy_sv)) croak("%_connections member is not a weakref");
if (!sv_derived_from(dpy_sv, "X11::Xlib")) croak("%_connections contains non-X11::Xlib object");
dpy= PerlXlib_get_magic_dpy(dpy_sv, 1 /* assert non-null */);
/* Check each of the objects in the $dpy->{_obj_cache} */
elem= hv_fetch((HV*)SvRV(dpy_sv), "_obj_cache", 10, 0);
if (elem) {
if (!*elem || !SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVHV)
croak("Display contains invalid _obj_cache");
if (SvREFCNT(*elem) != 1 || SvREFCNT(SvRV(*elem)) != 1)
croak("_obj_cache has wrong refcnt");
obj_cache= (HV*) SvRV(*elem);
/*hv_assert(obj_cache);*/
for (hv_iterinit(obj_cache); (obj_he= hv_iternext(dpys)); ) {
obj_sv= hv_iterval(obj_cache, obj_he);
if (SvREFCNT(obj_sv) != 1) croak("Refcnt of _obj_cache member is %d", SvREFCNT(obj_sv));
if (!SvROK(obj_sv) || !SvWEAKREF(obj_sv)) croak("_obj_cache member is not a weakref");
if (!sv_derived_from(obj_sv, "X11::Xlib::Opaque")) croak("_obj_cache member is not a X11::Xlib::Opaque");
opaque= (SvTYPE(SvRV(obj_sv)) <= SVt_PVMG)? INT2PTR(void*, SvIV(SvRV(obj_sv)))
: PerlXlib_get_magic_dpy_innerptr(obj_sv, 1 /* not null */);
/* the pointer should have a ->display attribute attached */
elem= hv_fetch(display_attr, (void*) &opaque, sizeof(void*), 0);
if (!elem || !*elem || !SvROK(*elem))
croak("Missing or invalid _display_attr{} reference");
if (SvREFCNT(*elem) != 1 || SvWEAKREF(*elem))
croak("_display_attr ref is not strongref with refcnt==1");
if (SvRV(dpy_sv) != SvRV(*elem))
croak("_display_attr points to wrong dpy_sv");
}
}
}
}
/* Xlib warns that some structs might change size, and provide "XAllocFoo"
* functions. However, this only solves the case of Xlib access violations
* from an old perl module on a new Xlib. New perl modules on old Xlib would
* still write beyond the buffer (on the perl side) and corrupt memory.
* Annoyingly, Xlib doesn't seem to have any way to query the size of the struct,
* only allocate it.
* Instead of using XAllocFoo sillyness (and the memory management hassle it
* would cause), just pad the struct with some extra bytes.
* Perl modules will probably always be compiled fresh anyway.
*/
#ifndef X11_Xlib_Struct_Padding
#define X11_Xlib_Struct_Padding 64
#endif
/* Coercions allowed for RValue:
* foo( "buffer_of_the_correct_length_or_more" );
* foo( \"ref_to_buffer_of_the_correct_length_or_more" );
* foo( \%hashref_of_fields );
* foo( bless(\"buffer_of_correct_length_or_more", "pkg_or_subclass") )
* Coercions allowed for LValue:
* foo( my $x= undef );
* foo( "buffer_of_correct_length_or_more" );
* foo( \(my $x= undef) );
* foo( \"buffer_of_correct_length_or_more" );
* foo( bless(\"buffer_of_correct_length_or_more", "any_struct_class") )
*/
void* PerlXlib_get_struct_ptr(SV *sv, int lvalue, const char* pkg, int struct_size, PerlXlib_struct_pack_fn *packer) {
SV *tmp, *refsv= NULL;
void* buf;
size_t n;
if (SvROK(sv)) {
refsv= sv;
sv= SvRV(sv);
/* Follow scalar refs, to get to the buffer of a blessed object */
if (SvTYPE(sv) == SVt_PVMG) {
/* If it is a blessed object, ensure the type matches */
if (sv_isobject(refsv) && !sv_isa(refsv, pkg)) {
if (!sv_derived_from(refsv, lvalue? "X11::Xlib::Struct" : pkg)) {
buf= SvPV(refsv, n);
croak("Can't coerce %.*s to %s %s", n, buf, pkg, lvalue? "lvalue":"rvalue");
}
}
}
/* Also accept a hashref, which we pass to "pack" */
else if (SvTYPE(sv) == SVt_PVHV) {
if (lvalue) croak("Can't coerce hashref to %s lvalue", pkg);
/* Need a buffer that lasts for the rest of our XS call stack.
* Cheat by using a mortal SV :-)
*/
tmp= sv_2mortal(newSV(struct_size + X11_Xlib_Struct_Padding));
buf= SvPVX(tmp);
memset(buf, 0, struct_size);
packer(buf, (HV*) sv, 0);
return buf;
}
else if (SvTYPE(sv) >= SVt_PVAV) { /* not a scalar */
buf= SvPV(refsv, n);
croak("Can't coerce %.*s to %s %s", n, buf, pkg, lvalue? "lvalue":"rvalue");
}
}
/* If uninitialized, initialize to a blessed struct object,
* unless we're looking at \undef in which case just initialize to a string
*/
if (!SvOK(sv)) {
if (!lvalue) croak("Can't coerce %sundef to %s rvalue", refsv? "\\" : "", pkg);
if (!refsv) {
refsv= sv, sv= newSVrv(sv, pkg);
/* sv is now the referenced scalar, which is undef, and gets inflated next */
}
sv_setpvn(sv, "", 0);
SvGROW(sv, struct_size+X11_Xlib_Struct_Padding);
SvCUR_set(sv, struct_size);
memset(SvPVX(sv), 0, struct_size+1);
}
else if (!SvPOK(sv))
croak("Paramters requiring %s can only be coerced from string, string ref, hashref, or undef", pkg);
else if (SvCUR(sv) < struct_size)
croak("Scalars used as %s must be at least length %d (got %d)", pkg, struct_size, SvCUR(sv));
/* Make sure we have the padding even if the user tinkered with the buffer */
SvPV_force(sv, n);
SvGROW(sv, struct_size+X11_Xlib_Struct_Padding);
return SvPVX(sv);
}
#include "keysym_to_codepoint.c"
KeySym PerlXlib_codepoint_to_keysym(int uc) {
/* Latin-1 is identical */
if ((uc >= 0x0020 && uc <= 0x007E) || (uc >= 0x00A0 && uc <= 0x00FF))
return uc;
/* Unicode in range 0..0xFFFFFF can be stored directly */
if ((uc & 0xFFFFFF) == uc)
return 0x1000000 | uc;
return NoSymbol;
}
SV * PerlXlib_keysym_to_sv(KeySym sym, int symbolic) {
int sym_codepoint;
const char *symname;
if (sym == NoSymbol)
return &PL_sv_undef;
/* Only convert to unicode character if reverse mapping matches forward mapping */
if (symbolic >= 2
&& (sym_codepoint= PerlXlib_keysym_to_codepoint(sym)) >= 0
&& (PerlXlib_codepoint_to_keysym(sym_codepoint) == sym))
return newSVpvf("%c", sym_codepoint);
/* Fall back to symbol name, but ensure reverse mapping here, as well */
else if (symbolic >= 1
&& sym > 0
&& (symname= XKeysymToString(sym))
&& (XStringToKeysym(symname) == sym))
return newSVpv(symname, 0);
/* Else just use the symbol ID */
else if (!symbolic || sym > 9)
return newSViv(sym);
/* Else it's ambiguous! Can't be loaded symbolicly. */
else
return NULL;
}
KeySym PerlXlib_sv_to_keysym(SV *sv) {
size_t len;
long ival, codepoint;
KeySym sym;
char *name, *endp;
if (!sv || !SvOK(sv))
return NoSymbol;
/* First try to process it as an X11 symbol name */
name= SvPV(sv, len);
sym= XStringToKeysym(name);
/* Else, use multi-digit numbers directly, and single-digit as a char lookup */
if (sym == NoSymbol) {
if (SvIOK(sv) && SvIV(sv) > 9)
sym= SvIV(sv);
else if ((ival= strtol(name, &endp, 0)) && (endp - name > 1) && *endp == 0)
sym= ival;
/* If it is a single character, try looking up a keysym for it */
else if ((DO_UTF8(sv)? sv_len_utf8(sv) : len) == 1) {
codepoint= NATIVE_TO_UNI(DO_UTF8(sv)? utf8n_to_uvchr(name, len, &len, 0) : (name[0] & 0xFF));
sym= PerlXlib_codepoint_to_keysym(codepoint);
}
}
return sym;
}
int PerlXlib_X_error_handler(Display *d, XErrorEvent *e) {
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
EXTEND(SP, 1);
PUSHs(sv_2mortal(sv_setref_pvn(newSV(0), "X11::Xlib::XErrorEvent", (void*) e, sizeof(XEvent))));
PUTBACK;
call_pv("X11::Xlib::_error_nonfatal", G_VOID|G_DISCARD|G_EVAL|G_KEEPERR);
FREETMPS;
LEAVE;
return 0;
}
/*
What a mess. So Xlib has a stupid design where they forcibly abort the
program when an I/O error occurs and the X server is lost. Even if you
install the error handler, they expect you to abort the program and they
do it for you if you return. Furthermore, they tell you that you may not
call any more Xlib functions at all.
Luckily we can cheat with croak (longjmp) back out of the callback and
avoid the forced program exit. However now we can't officially use Xlib
again for the duration of the program, and there could be lost resources
from our longjmp. So, set a global flag to prevent any re-entry into XLib.
*/
int PerlXlib_X_IO_error_handler(Display *d) {
sv_setiv(get_sv("X11::Xlib::_error_fatal_trapped", GV_ADD), 1);
warn("Xlib fatal error. Further calls to Xlib are forbidden.");
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
EXTEND(SP, 1);
PUSHs(PerlXlib_obj_for_display(d, 1));
PUTBACK;
call_pv("X11::Xlib::_error_fatal", G_VOID|G_DISCARD|G_EVAL|G_KEEPERR);
FREETMPS;
LEAVE;
croak("Fatal X11 I/O Error"); /* longjmp past Xlib, which wants to kill us */
return 0; /* never reached. Make compiler happy. */
}
/* Install the Xlib error handlers, only if they have not already been installed.
* Use perl scalars to store this status, to avoid threading issues and to
* give users potential to inspect.
*/
void PerlXlib_install_error_handlers(Bool nonfatal, Bool fatal) {
SV *nonfatal_installed= get_sv("X11::Xlib::_error_nonfatal_installed", GV_ADD);
SV *fatal_installed= get_sv("X11::Xlib::_error_fatal_installed", GV_ADD);
if (nonfatal && !SvTRUE(nonfatal_installed)) {
XSetErrorHandler(&PerlXlib_X_error_handler);
sv_setiv(nonfatal_installed, 1);
}
if (fatal && !SvTRUE(fatal_installed)) {
XSetIOErrorHandler(&PerlXlib_X_IO_error_handler);
sv_setiv(fatal_installed, 1);
}
}
/*--------------------------------------------------------------------------*/
/* BEGIN GENERATED X11_Xlib_XEvent */
const char* PerlXlib_xevent_pkg_for_type(int type) {
switch (type) {
case 0: return "X11::Xlib::XErrorEvent";
case ButtonPress: return "X11::Xlib::XButtonEvent";
case ButtonRelease: return "X11::Xlib::XButtonEvent";
case CirculateNotify: return "X11::Xlib::XCirculateEvent";
case CirculateRequest: return "X11::Xlib::XCirculateRequestEvent";
case ClientMessage: return "X11::Xlib::XClientMessageEvent";
case ColormapNotify: return "X11::Xlib::XColormapEvent";
case ConfigureNotify: return "X11::Xlib::XConfigureEvent";
case ConfigureRequest: return "X11::Xlib::XConfigureRequestEvent";
case CreateNotify: return "X11::Xlib::XCreateWindowEvent";
case DestroyNotify: return "X11::Xlib::XDestroyWindowEvent";
case EnterNotify: return "X11::Xlib::XCrossingEvent";
case Expose: return "X11::Xlib::XExposeEvent";
case FocusIn: return "X11::Xlib::XFocusChangeEvent";
case FocusOut: return "X11::Xlib::XFocusChangeEvent";
case GenericEvent: return "X11::Xlib::XGenericEvent";
case GraphicsExpose: return "X11::Xlib::XGraphicsExposeEvent";
case GravityNotify: return "X11::Xlib::XGravityEvent";
case KeyPress: return "X11::Xlib::XKeyEvent";
case KeyRelease: return "X11::Xlib::XKeyEvent";
case KeymapNotify: return "X11::Xlib::XKeymapEvent";
case LeaveNotify: return "X11::Xlib::XCrossingEvent";
case MapNotify: return "X11::Xlib::XMapEvent";
case MapRequest: return "X11::Xlib::XMapRequestEvent";
case MappingNotify: return "X11::Xlib::XMappingEvent";
case MotionNotify: return "X11::Xlib::XMotionEvent";
case NoExpose: return "X11::Xlib::XNoExposeEvent";
case PropertyNotify: return "X11::Xlib::XPropertyEvent";
case ReparentNotify: return "X11::Xlib::XReparentEvent";
case ResizeRequest: return "X11::Xlib::XResizeRequestEvent";
case SelectionClear: return "X11::Xlib::XSelectionClearEvent";
case SelectionNotify: return "X11::Xlib::XSelectionEvent";
case SelectionRequest: return "X11::Xlib::XSelectionRequestEvent";
case UnmapNotify: return "X11::Xlib::XUnmapEvent";
case VisibilityNotify: return "X11::Xlib::XVisibilityEvent";
default: return "X11::Xlib::XEvent";
}
}
/* First, pack type, then pack fields for XAnyEvent, then any fields known for that type */
void PerlXlib_XEvent_pack(XEvent *s, HV *fields, Bool consume) {
SV **fp;
int newtype;
const char *oldpkg, *newpkg;
/* Type gets special handling */
fp= hv_fetch(fields, "type", 4, 0);
if (fp && *fp) {
newtype= SvIV(*fp);
if (s->type != newtype) {
oldpkg= PerlXlib_xevent_pkg_for_type(s->type);
newpkg= PerlXlib_xevent_pkg_for_type(newtype);
s->type= newtype;
if (oldpkg != newpkg) {
/* re-initialize all fields in the area that changed */
memset( ((char*)(void*)s) + sizeof(XAnyEvent), 0, sizeof(XEvent)-sizeof(XAnyEvent) );
}
}
if (consume) hv_delete(fields, "type", 4, G_DISCARD);
}
if (s->type) {
fp= hv_fetch(fields, "display", 7, 0);
if (fp && *fp) { s->xany.display= PerlXlib_get_magic_dpy(*fp, 0);; if (consume) hv_delete(fields, "display", 7, G_DISCARD); }
fp= hv_fetch(fields, "send_event", 10, 0);
if (fp && *fp) { s->xany.send_event= SvIV(*fp);; if (consume) hv_delete(fields, "send_event", 10, G_DISCARD); }
fp= hv_fetch(fields, "serial", 6, 0);
if (fp && *fp) { s->xany.serial= SvUV(*fp);; if (consume) hv_delete(fields, "serial", 6, G_DISCARD); }
fp= hv_fetch(fields, "type", 4, 0);
if (fp && *fp) { s->xany.type= SvIV(*fp);; if (consume) hv_delete(fields, "type", 4, G_DISCARD); }
}
else {
fp= hv_fetch(fields, "serial", 6, 0);
if (fp && *fp) { s->xerror.serial= SvUV(*fp);; if (consume) hv_delete(fields, "serial", 6, G_DISCARD); }
fp= hv_fetch(fields, "display", 7, 0);
if (fp && *fp) { s->xerror.display= PerlXlib_get_magic_dpy(*fp, 0);; if (consume) hv_delete(fields, "display", 7, G_DISCARD); }
}
switch( s->type ) {
case ButtonPress:
case ButtonRelease:
fp= hv_fetch(fields, "button", 6, 0);
if (fp && *fp) { s->xbutton.button= SvUV(*fp);; if (consume) hv_delete(fields, "button", 6, G_DISCARD); }
fp= hv_fetch(fields, "root", 4, 0);
if (fp && *fp) { s->xbutton.root= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "root", 4, G_DISCARD); }
fp= hv_fetch(fields, "same_screen", 11, 0);
if (fp && *fp) { s->xbutton.same_screen= SvIV(*fp);; if (consume) hv_delete(fields, "same_screen", 11, G_DISCARD); }
fp= hv_fetch(fields, "state", 5, 0);
if (fp && *fp) { s->xbutton.state= SvUV(*fp);; if (consume) hv_delete(fields, "state", 5, G_DISCARD); }
fp= hv_fetch(fields, "subwindow", 9, 0);
if (fp && *fp) { s->xbutton.subwindow= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "subwindow", 9, G_DISCARD); }
fp= hv_fetch(fields, "time", 4, 0);
if (fp && *fp) { s->xbutton.time= SvUV(*fp);; if (consume) hv_delete(fields, "time", 4, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xbutton.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xbutton.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "x_root", 6, 0);
if (fp && *fp) { s->xbutton.x_root= SvIV(*fp);; if (consume) hv_delete(fields, "x_root", 6, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xbutton.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
fp= hv_fetch(fields, "y_root", 6, 0);
if (fp && *fp) { s->xbutton.y_root= SvIV(*fp);; if (consume) hv_delete(fields, "y_root", 6, G_DISCARD); }
break;
case CirculateNotify:
fp= hv_fetch(fields, "event", 5, 0);
if (fp && *fp) { s->xcirculate.event= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "event", 5, G_DISCARD); }
fp= hv_fetch(fields, "place", 5, 0);
if (fp && *fp) { s->xcirculate.place= SvIV(*fp);; if (consume) hv_delete(fields, "place", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xcirculate.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case CirculateRequest:
fp= hv_fetch(fields, "parent", 6, 0);
if (fp && *fp) { s->xcirculaterequest.parent= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "parent", 6, G_DISCARD); }
fp= hv_fetch(fields, "place", 5, 0);
if (fp && *fp) { s->xcirculaterequest.place= SvIV(*fp);; if (consume) hv_delete(fields, "place", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xcirculaterequest.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case ClientMessage:
fp= hv_fetch(fields, "b", 1, 0);
if (fp && *fp) { { if (!SvPOK(*fp) || SvCUR(*fp) != sizeof(char)*20) croak("Expected scalar of length %d but got %d", sizeof(char)*20, SvCUR(*fp)); memcpy(s->xclient.data.b, SvPVX(*fp), sizeof(char)*20);}; if (consume) hv_delete(fields, "b", 1, G_DISCARD); }
fp= hv_fetch(fields, "l", 1, 0);
if (fp && *fp) { { if (!SvPOK(*fp) || SvCUR(*fp) != sizeof(long)*5) croak("Expected scalar of length %d but got %d", sizeof(long)*5, SvCUR(*fp)); memcpy(s->xclient.data.l, SvPVX(*fp), sizeof(long)*5);}; if (consume) hv_delete(fields, "l", 1, G_DISCARD); }
fp= hv_fetch(fields, "s", 1, 0);
if (fp && *fp) { { if (!SvPOK(*fp) || SvCUR(*fp) != sizeof(short)*10) croak("Expected scalar of length %d but got %d", sizeof(short)*10, SvCUR(*fp)); memcpy(s->xclient.data.s, SvPVX(*fp), sizeof(short)*10);}; if (consume) hv_delete(fields, "s", 1, G_DISCARD); }
fp= hv_fetch(fields, "format", 6, 0);
if (fp && *fp) { s->xclient.format= SvIV(*fp);; if (consume) hv_delete(fields, "format", 6, G_DISCARD); }
fp= hv_fetch(fields, "message_type", 12, 0);
if (fp && *fp) { s->xclient.message_type= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "message_type", 12, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xclient.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case ColormapNotify:
fp= hv_fetch(fields, "colormap", 8, 0);
if (fp && *fp) { s->xcolormap.colormap= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "colormap", 8, G_DISCARD); }
fp= hv_fetch(fields, "new", 3, 0);
if (fp && *fp) { s->xcolormap.new= SvIV(*fp);; if (consume) hv_delete(fields, "new", 3, G_DISCARD); }
fp= hv_fetch(fields, "state", 5, 0);
if (fp && *fp) { s->xcolormap.state= SvIV(*fp);; if (consume) hv_delete(fields, "state", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xcolormap.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case ConfigureNotify:
fp= hv_fetch(fields, "above", 5, 0);
if (fp && *fp) { s->xconfigure.above= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "above", 5, G_DISCARD); }
fp= hv_fetch(fields, "border_width", 12, 0);
if (fp && *fp) { s->xconfigure.border_width= SvIV(*fp);; if (consume) hv_delete(fields, "border_width", 12, G_DISCARD); }
fp= hv_fetch(fields, "event", 5, 0);
if (fp && *fp) { s->xconfigure.event= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "event", 5, G_DISCARD); }
fp= hv_fetch(fields, "height", 6, 0);
if (fp && *fp) { s->xconfigure.height= SvIV(*fp);; if (consume) hv_delete(fields, "height", 6, G_DISCARD); }
fp= hv_fetch(fields, "override_redirect", 17, 0);
if (fp && *fp) { s->xconfigure.override_redirect= SvIV(*fp);; if (consume) hv_delete(fields, "override_redirect", 17, G_DISCARD); }
fp= hv_fetch(fields, "width", 5, 0);
if (fp && *fp) { s->xconfigure.width= SvIV(*fp);; if (consume) hv_delete(fields, "width", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xconfigure.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xconfigure.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xconfigure.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
break;
case ConfigureRequest:
fp= hv_fetch(fields, "above", 5, 0);
if (fp && *fp) { s->xconfigurerequest.above= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "above", 5, G_DISCARD); }
fp= hv_fetch(fields, "border_width", 12, 0);
if (fp && *fp) { s->xconfigurerequest.border_width= SvIV(*fp);; if (consume) hv_delete(fields, "border_width", 12, G_DISCARD); }
fp= hv_fetch(fields, "detail", 6, 0);
if (fp && *fp) { s->xconfigurerequest.detail= SvIV(*fp);; if (consume) hv_delete(fields, "detail", 6, G_DISCARD); }
fp= hv_fetch(fields, "height", 6, 0);
if (fp && *fp) { s->xconfigurerequest.height= SvIV(*fp);; if (consume) hv_delete(fields, "height", 6, G_DISCARD); }
fp= hv_fetch(fields, "parent", 6, 0);
if (fp && *fp) { s->xconfigurerequest.parent= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "parent", 6, G_DISCARD); }
fp= hv_fetch(fields, "value_mask", 10, 0);
if (fp && *fp) { s->xconfigurerequest.value_mask= SvUV(*fp);; if (consume) hv_delete(fields, "value_mask", 10, G_DISCARD); }
fp= hv_fetch(fields, "width", 5, 0);
if (fp && *fp) { s->xconfigurerequest.width= SvIV(*fp);; if (consume) hv_delete(fields, "width", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xconfigurerequest.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xconfigurerequest.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xconfigurerequest.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
break;
case CreateNotify:
fp= hv_fetch(fields, "border_width", 12, 0);
if (fp && *fp) { s->xcreatewindow.border_width= SvIV(*fp);; if (consume) hv_delete(fields, "border_width", 12, G_DISCARD); }
fp= hv_fetch(fields, "height", 6, 0);
if (fp && *fp) { s->xcreatewindow.height= SvIV(*fp);; if (consume) hv_delete(fields, "height", 6, G_DISCARD); }
fp= hv_fetch(fields, "override_redirect", 17, 0);
if (fp && *fp) { s->xcreatewindow.override_redirect= SvIV(*fp);; if (consume) hv_delete(fields, "override_redirect", 17, G_DISCARD); }
fp= hv_fetch(fields, "parent", 6, 0);
if (fp && *fp) { s->xcreatewindow.parent= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "parent", 6, G_DISCARD); }
fp= hv_fetch(fields, "width", 5, 0);
if (fp && *fp) { s->xcreatewindow.width= SvIV(*fp);; if (consume) hv_delete(fields, "width", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xcreatewindow.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xcreatewindow.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xcreatewindow.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
break;
case EnterNotify:
case LeaveNotify:
fp= hv_fetch(fields, "detail", 6, 0);
if (fp && *fp) { s->xcrossing.detail= SvIV(*fp);; if (consume) hv_delete(fields, "detail", 6, G_DISCARD); }
fp= hv_fetch(fields, "focus", 5, 0);
if (fp && *fp) { s->xcrossing.focus= SvIV(*fp);; if (consume) hv_delete(fields, "focus", 5, G_DISCARD); }
fp= hv_fetch(fields, "mode", 4, 0);
if (fp && *fp) { s->xcrossing.mode= SvIV(*fp);; if (consume) hv_delete(fields, "mode", 4, G_DISCARD); }
fp= hv_fetch(fields, "root", 4, 0);
if (fp && *fp) { s->xcrossing.root= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "root", 4, G_DISCARD); }
fp= hv_fetch(fields, "same_screen", 11, 0);
if (fp && *fp) { s->xcrossing.same_screen= SvIV(*fp);; if (consume) hv_delete(fields, "same_screen", 11, G_DISCARD); }
fp= hv_fetch(fields, "state", 5, 0);
if (fp && *fp) { s->xcrossing.state= SvUV(*fp);; if (consume) hv_delete(fields, "state", 5, G_DISCARD); }
fp= hv_fetch(fields, "subwindow", 9, 0);
if (fp && *fp) { s->xcrossing.subwindow= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "subwindow", 9, G_DISCARD); }
fp= hv_fetch(fields, "time", 4, 0);
if (fp && *fp) { s->xcrossing.time= SvUV(*fp);; if (consume) hv_delete(fields, "time", 4, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xcrossing.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xcrossing.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "x_root", 6, 0);
if (fp && *fp) { s->xcrossing.x_root= SvIV(*fp);; if (consume) hv_delete(fields, "x_root", 6, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xcrossing.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
fp= hv_fetch(fields, "y_root", 6, 0);
if (fp && *fp) { s->xcrossing.y_root= SvIV(*fp);; if (consume) hv_delete(fields, "y_root", 6, G_DISCARD); }
break;
case DestroyNotify:
fp= hv_fetch(fields, "event", 5, 0);
if (fp && *fp) { s->xdestroywindow.event= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "event", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xdestroywindow.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case 0:
fp= hv_fetch(fields, "error_code", 10, 0);
if (fp && *fp) { s->xerror.error_code= SvUV(*fp);; if (consume) hv_delete(fields, "error_code", 10, G_DISCARD); }
fp= hv_fetch(fields, "minor_code", 10, 0);
if (fp && *fp) { s->xerror.minor_code= SvUV(*fp);; if (consume) hv_delete(fields, "minor_code", 10, G_DISCARD); }
fp= hv_fetch(fields, "request_code", 12, 0);
if (fp && *fp) { s->xerror.request_code= SvUV(*fp);; if (consume) hv_delete(fields, "request_code", 12, G_DISCARD); }
fp= hv_fetch(fields, "resourceid", 10, 0);
if (fp && *fp) { s->xerror.resourceid= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "resourceid", 10, G_DISCARD); }
break;
case Expose:
fp= hv_fetch(fields, "count", 5, 0);
if (fp && *fp) { s->xexpose.count= SvIV(*fp);; if (consume) hv_delete(fields, "count", 5, G_DISCARD); }
fp= hv_fetch(fields, "height", 6, 0);
if (fp && *fp) { s->xexpose.height= SvIV(*fp);; if (consume) hv_delete(fields, "height", 6, G_DISCARD); }
fp= hv_fetch(fields, "width", 5, 0);
if (fp && *fp) { s->xexpose.width= SvIV(*fp);; if (consume) hv_delete(fields, "width", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xexpose.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xexpose.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xexpose.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
break;
case FocusIn:
case FocusOut:
fp= hv_fetch(fields, "detail", 6, 0);
if (fp && *fp) { s->xfocus.detail= SvIV(*fp);; if (consume) hv_delete(fields, "detail", 6, G_DISCARD); }
fp= hv_fetch(fields, "mode", 4, 0);
if (fp && *fp) { s->xfocus.mode= SvIV(*fp);; if (consume) hv_delete(fields, "mode", 4, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xfocus.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case GenericEvent:
fp= hv_fetch(fields, "evtype", 6, 0);
if (fp && *fp) { s->xgeneric.evtype= SvIV(*fp);; if (consume) hv_delete(fields, "evtype", 6, G_DISCARD); }
fp= hv_fetch(fields, "extension", 9, 0);
if (fp && *fp) { s->xgeneric.extension= SvIV(*fp);; if (consume) hv_delete(fields, "extension", 9, G_DISCARD); }
break;
case GraphicsExpose:
fp= hv_fetch(fields, "count", 5, 0);
if (fp && *fp) { s->xgraphicsexpose.count= SvIV(*fp);; if (consume) hv_delete(fields, "count", 5, G_DISCARD); }
fp= hv_fetch(fields, "drawable", 8, 0);
if (fp && *fp) { s->xgraphicsexpose.drawable= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "drawable", 8, G_DISCARD); }
fp= hv_fetch(fields, "height", 6, 0);
if (fp && *fp) { s->xgraphicsexpose.height= SvIV(*fp);; if (consume) hv_delete(fields, "height", 6, G_DISCARD); }
fp= hv_fetch(fields, "major_code", 10, 0);
if (fp && *fp) { s->xgraphicsexpose.major_code= SvIV(*fp);; if (consume) hv_delete(fields, "major_code", 10, G_DISCARD); }
fp= hv_fetch(fields, "minor_code", 10, 0);
if (fp && *fp) { s->xgraphicsexpose.minor_code= SvIV(*fp);; if (consume) hv_delete(fields, "minor_code", 10, G_DISCARD); }
fp= hv_fetch(fields, "width", 5, 0);
if (fp && *fp) { s->xgraphicsexpose.width= SvIV(*fp);; if (consume) hv_delete(fields, "width", 5, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xgraphicsexpose.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xgraphicsexpose.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
break;
case GravityNotify:
fp= hv_fetch(fields, "event", 5, 0);
if (fp && *fp) { s->xgravity.event= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "event", 5, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xgravity.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xgravity.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xgravity.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
break;
case KeyPress:
case KeyRelease:
fp= hv_fetch(fields, "keycode", 7, 0);
if (fp && *fp) { s->xkey.keycode= SvUV(*fp);; if (consume) hv_delete(fields, "keycode", 7, G_DISCARD); }
fp= hv_fetch(fields, "root", 4, 0);
if (fp && *fp) { s->xkey.root= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "root", 4, G_DISCARD); }
fp= hv_fetch(fields, "same_screen", 11, 0);
if (fp && *fp) { s->xkey.same_screen= SvIV(*fp);; if (consume) hv_delete(fields, "same_screen", 11, G_DISCARD); }
fp= hv_fetch(fields, "state", 5, 0);
if (fp && *fp) { s->xkey.state= SvUV(*fp);; if (consume) hv_delete(fields, "state", 5, G_DISCARD); }
fp= hv_fetch(fields, "subwindow", 9, 0);
if (fp && *fp) { s->xkey.subwindow= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "subwindow", 9, G_DISCARD); }
fp= hv_fetch(fields, "time", 4, 0);
if (fp && *fp) { s->xkey.time= SvUV(*fp);; if (consume) hv_delete(fields, "time", 4, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xkey.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xkey.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "x_root", 6, 0);
if (fp && *fp) { s->xkey.x_root= SvIV(*fp);; if (consume) hv_delete(fields, "x_root", 6, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xkey.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
fp= hv_fetch(fields, "y_root", 6, 0);
if (fp && *fp) { s->xkey.y_root= SvIV(*fp);; if (consume) hv_delete(fields, "y_root", 6, G_DISCARD); }
break;
case KeymapNotify:
fp= hv_fetch(fields, "key_vector", 10, 0);
if (fp && *fp) { { if (!SvPOK(*fp) || SvCUR(*fp) != sizeof(char)*32) croak("Expected scalar of length %d but got %d", sizeof(char)*32, SvCUR(*fp)); memcpy(s->xkeymap.key_vector, SvPVX(*fp), sizeof(char)*32);}; if (consume) hv_delete(fields, "key_vector", 10, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xkeymap.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case MapNotify:
fp= hv_fetch(fields, "event", 5, 0);
if (fp && *fp) { s->xmap.event= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "event", 5, G_DISCARD); }
fp= hv_fetch(fields, "override_redirect", 17, 0);
if (fp && *fp) { s->xmap.override_redirect= SvIV(*fp);; if (consume) hv_delete(fields, "override_redirect", 17, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xmap.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case MappingNotify:
fp= hv_fetch(fields, "count", 5, 0);
if (fp && *fp) { s->xmapping.count= SvIV(*fp);; if (consume) hv_delete(fields, "count", 5, G_DISCARD); }
fp= hv_fetch(fields, "first_keycode", 13, 0);
if (fp && *fp) { s->xmapping.first_keycode= SvIV(*fp);; if (consume) hv_delete(fields, "first_keycode", 13, G_DISCARD); }
fp= hv_fetch(fields, "request", 7, 0);
if (fp && *fp) { s->xmapping.request= SvIV(*fp);; if (consume) hv_delete(fields, "request", 7, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xmapping.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case MapRequest:
fp= hv_fetch(fields, "parent", 6, 0);
if (fp && *fp) { s->xmaprequest.parent= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "parent", 6, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xmaprequest.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
break;
case MotionNotify:
fp= hv_fetch(fields, "is_hint", 7, 0);
if (fp && *fp) { s->xmotion.is_hint= SvIV(*fp);; if (consume) hv_delete(fields, "is_hint", 7, G_DISCARD); }
fp= hv_fetch(fields, "root", 4, 0);
if (fp && *fp) { s->xmotion.root= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "root", 4, G_DISCARD); }
fp= hv_fetch(fields, "same_screen", 11, 0);
if (fp && *fp) { s->xmotion.same_screen= SvIV(*fp);; if (consume) hv_delete(fields, "same_screen", 11, G_DISCARD); }
fp= hv_fetch(fields, "state", 5, 0);
if (fp && *fp) { s->xmotion.state= SvUV(*fp);; if (consume) hv_delete(fields, "state", 5, G_DISCARD); }
fp= hv_fetch(fields, "subwindow", 9, 0);
if (fp && *fp) { s->xmotion.subwindow= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "subwindow", 9, G_DISCARD); }
fp= hv_fetch(fields, "time", 4, 0);
if (fp && *fp) { s->xmotion.time= SvUV(*fp);; if (consume) hv_delete(fields, "time", 4, G_DISCARD); }
fp= hv_fetch(fields, "window", 6, 0);
if (fp && *fp) { s->xmotion.window= PerlXlib_sv_to_xid(*fp);; if (consume) hv_delete(fields, "window", 6, G_DISCARD); }
fp= hv_fetch(fields, "x", 1, 0);
if (fp && *fp) { s->xmotion.x= SvIV(*fp);; if (consume) hv_delete(fields, "x", 1, G_DISCARD); }
fp= hv_fetch(fields, "x_root", 6, 0);
if (fp && *fp) { s->xmotion.x_root= SvIV(*fp);; if (consume) hv_delete(fields, "x_root", 6, G_DISCARD); }
fp= hv_fetch(fields, "y", 1, 0);
if (fp && *fp) { s->xmotion.y= SvIV(*fp);; if (consume) hv_delete(fields, "y", 1, G_DISCARD); }
fp= hv_fetch(fields, "y_root", 6, 0);
if (fp && *fp) { s->xmotion.y_root= SvIV(*fp);; if (consume) hv_delete(fields, "y_root", 6, G_DISCARD); }
break;