/
Guitor.winxed
2879 lines (2801 loc) · 85 KB
/
Guitor.winxed
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
#! winxed
// Guitor.winxed
// Xlib module via parrot NCI.
$include "GuitorConstants.winxhead";
$include_const "hash_key_type.pasm";
$load "GuitorNci.pbc";
namespace Guitor
{
$include_const "datatypes.pasm";
//**************************************************************
// Internal helper functions
//**************************************************************
namespace Xlib__private
{
extern function str_to_achar;
extern function str_to_achar_utf8;
extern function str_to_cstring;
extern function string_from_nci;
extern function getfun;
extern function getxftfun;
extern function getxpmfun;
extern function geteventpad;
extern function getanyview;
extern function getstructureview;
extern function getexposeview;
extern function getcrossingview;
extern function getfocusview;
extern function getmapview;
extern function getmotionview;
extern function getbuttonview;
extern function getkeyview;
extern function getselectionclearview;
extern function getselectionrequestview;
extern function getselectionview;
extern function getclientview;
extern function getxcolorview;
extern function getxftcolorview;
extern function getxftfontview;
extern function getxfontview;
extern function getatomview;
extern function getglyphinfoview;
extern function getview;
extern function newAtomlist;
function XFree(p)
{
getfun("XFree")(p);
}
} // namespace Xlib__private
using namespace Xlib__private;
using namespace Events;
//**************************************************************
// Display
//**************************************************************
class Display
{
var xdisplay;
var default_screen;
var default_font;
var xim;
function Display(string displayname[optional])
{
__DEBUG__ && cry(__FUNCTION__);
var d;
if (displayname == null)
displayname = "";
d = str_to_cstring(displayname);
self.xdisplay = getfun("XOpenDisplay")(d);
getfun("setlocale")(0, str_to_cstring(""));
getfun("XSetLocaleModifiers")(str_to_cstring(""));
self.default_screen = self._DefaultScreen();
}
function Close()
{
__DEBUG__ && cry("Display.Close");
getfun("XCloseDisplay")(self.xdisplay);
self.xdisplay = null;
__DEBUG__ && cry("closed");
}
function Flush()
{
getfun("XFlush")(self.xdisplay);
}
function Sync(int discard)
{
getfun("XSync")(self.xdisplay, discard);
}
function _DefaultScreen()
{
int scrnum = getfun("XDefaultScreen")(self.xdisplay);
return scrnum;
}
function DefaultScreen()
{
return int(self.default_screen);
}
function DefaultDepth(int scrnum)
{
int depth = getfun("XDefaultDepth")(self.xdisplay, scrnum);
return depth;
}
function DefaultVisual(int scrnum[optional])
{
return getfun("XDefaultVisual")(self.xdisplay, scrnum);
}
function DefaultColormap(int scrnum[optional])
{
return getfun("XDefaultColormap")(self.xdisplay, scrnum);
}
function Height(int scrnum[optional])
{
return int(getfun("XDisplayHeight")(self.xdisplay, scrnum));
}
function HeightMM(int scrnum[optional])
{
return int(getfun("XDisplayHeightMM")(self.xdisplay, scrnum));
}
function Width(int scrnum[optional])
{
return int(getfun("XDisplayWidth")(self.xdisplay, scrnum));
}
function WidthMM(int scrnum[optional])
{
return int(getfun("XDisplayWidthMM")(self.xdisplay, scrnum));
}
function BlackPixel(int scrnum)
{
return getfun("XBlackPixel")(self.xdisplay, scrnum);
}
function WhitePixel(int scrnum)
{
return getfun("XWhitePixel")(self.xdisplay, scrnum);
}
function KeycodeToKeysym(int keycode)
{
return getfun("XKeycodeToKeysym")(self.xdisplay, keycode, 0);
}
function KeysymToKeycode(int keysym)
{
return getfun("XKeysymToKeycode")(self.xdisplay, keysym);
}
function StringToKeysym(string keystring)
{
return getfun("XStringToKeysym")(str_to_cstring(keystring));
}
function KeysymToString(int keysym)
{
var fn = getfun("XKeysymToString");
return string_from_nci(fn(keysym));
}
function getIM()
{
var xim = self.xim;
if (self.xim == null) {
xim = getfun("XOpenIM")(self.xdisplay, null, null, null);
if (! xim)
xim = false;
self.xim = xim;
}
return xim;
}
function _LookupString(window, event)
{
const int BUFSIZE = 32;
var buffer = new ["ByteBuffer"];
buffer =: BUFSIZE;
int len;
var fun;
var xic = window.getIC();
if (xic == null || ! xic) {
fun = getfun("XLookupString");
len = fun(event.eventdata, buffer, BUFSIZE, null, null);
}
else {
fun = getfun("XmbLookupString");
len = fun(xic, event.eventdata, buffer, BUFSIZE, null, null);
}
string str;
if (len > 0) {
buffer =: len;
str = buffer.get_string("utf8");
}
return str;
}
function InternAtom(string name, int only_if_exists[optional])
{
__DEBUG__ && cry(__FUNCTION__);
var pname = str_to_cstring(name);
int atom = getfun("XInternAtom")(self.xdisplay, pname, only_if_exists);
return atom;
}
function GetAtomName(int atom)
{
__DEBUG__ && cry(__FUNCTION__);
var name = getfun("XGetAtomName")(self.xdisplay, atom);
string sname = name.as_string("ascii");
XFree(name);
return sname;
}
function AtomlistFromStrings(var atomnames)
{
__DEBUG__ && cry(__FUNCTION__);
int natoms = elements(atomnames);
var aux = newAtomlist(natoms);
var ast = getatomview(elements(atomnames));
for (int i = 0; i < natoms; ++i)
ast[aux, i] = int(self.InternAtom(atomnames[i]));
return aux;
}
function DefaultGC()
{
var fn = getfun("XDefaultGC");
return fn(self.xdisplay, self.default_screen);
}
function _RootWindow(int scrnum)
{
__DEBUG__ && cry(__FUNCTION__);
return getfun("XRootWindow")(self.xdisplay, scrnum);
}
function RootWindow(int scrnum)
{
__DEBUG__ && cry(__FUNCTION__);
var fn = getfun("XRootWindow");
var rootw = new Window;
rootw.display = self;
rootw.xdrawable = fn(self.xdisplay, scrnum);
return rootw;
}
function CreateSimpleWindow(var parent,
int x, int y, int width, int height,
int border_width, int border, int background)
{
__DEBUG__ && cry(__FUNCTION__);
var fn = getfun("XCreateSimpleWindow");
return fn(self.xdisplay, parent.xdrawable,
x, y, width, height, border_width, border, background);
}
function CreateSimpleWindow(int x, int y, int width, int height,
int border_width, int border, int background)
{
__DEBUG__ && cry(__FUNCTION__);
var fn = getfun("XCreateSimpleWindow");
return fn(self.xdisplay, self._RootWindow(0),
x, y, width, height, border_width, border, background);
}
function CreateSimpleWindow(int x, int y, int width, int height)
{
__DEBUG__ && cry(__FUNCTION__);
var fn = getfun("XCreateSimpleWindow");
return fn(self.xdisplay, self._RootWindow(0), x, y, width, height,
0, self.BlackPixel(0), self.WhitePixel(0));
}
function CreateSimpleChildWindow(parent, x, y, width, height,
int border_width, int border_color, int background)
{
__DEBUG__ && cry(__FUNCTION__);
var fn = getfun("XCreateSimpleWindow");
return fn(self.xdisplay, parent.xdrawable, x, y, width, height,
border_width, border_color, background);
}
function _DestroyWindow(int xwindow)
{
getfun("XDestroyWindow")(self.xdisplay, xwindow);
}
function Pending()
{
return int(getfun("XPending")(self.xdisplay));
}
function NextEvent(var event)
{
using namespace Events;
var fn = getfun("XNextEvent");
event._get(self.xdisplay, fn);
}
function SendEvent(int xwindow, int propagate, int event_mask, event)
{
getfun("XSendEvent")(self.xdisplay, xwindow,
propagate, event_mask, event.eventdata);
}
function WarpPointer(int xwindow, int x, int y)
{
getfun("XWarpPointer")(self.xdisplay, None, xwindow, 0, 0, 0, 0, x, y);
}
function SetWMProtocols(drawable, names)
{
__DEBUG__ && cry(__FUNCTION__);
var atomlist = self.AtomlistFromStrings(names);
var fn = getfun("XSetWMProtocols");
fn(self.xdisplay, drawable.xdrawable, atomlist, elements(names));
}
function ParseColor(string spec)
{
var xdisplay = self.xdisplay;
var colormap = self.DefaultColormap();
/*
var xcolorview = getxcolorview();
var xcolor = xcolorview.alloc();
int status = getfun("XParseColor")(xdisplay, colormap, str_to_cstring(spec), xcolor);
if (status) {
status = getfun("XAllocColor")(xdisplay, colormap, xcolor);
if (status)
return new Color(xcolor);
}
*/
var xftcolorview = getxftcolorview();
var xftcolor = xftcolorview.alloc();
var visual = self.DefaultVisual();
if (getxftfun("XftColorAllocName")(xdisplay, visual, colormap,
str_to_cstring(spec), xftcolor)) {
var color = new XftColor;
color.xftcolor = xftcolor;
return color;
}
return null;
}
function setDefaultFont(string fontdesc)
{
var font = self.default_font;
if (font == null) {
var ptr = new ["StructView"]( [DATATYPE_STRUCT, 1, DATATYPE_PTR ] );
var p1 = ptr.alloc();
var p2 = ptr.alloc();
var p3 = ptr.alloc();
var xfont = getfun("XCreateFontSet")(self.xdisplay,
str_to_cstring(fontdesc), p1, p2, p3);
if (xfont == null || ! xfont)
return false;
font = new FontSet;
font.xfont = xfont;
}
self.default_font = font;
return true;
}
function getDefaultFont()
{
var font = self.default_font;
if (font == null) {
self.setDefaultFont("-*-*-*-r-*-*-*-140-*");
font = self.default_font;
}
return font;
}
function CreateFont(string name)
{
var xdisplay = self.xdisplay;
var pname = str_to_cstring(name);
var fun = getxftfun("XftFontOpenXlfd");
if (fun == null)
throw "Xft not available";
var xftfont = fun(xdisplay, 0, pname);
if (xftfont == null) {
xftfont = getxftfun("XftFontOpenName")(xdisplay, 0, pname);
if (xftfont == null)
return null;
}
var font = new XftFont;
font.xftfont = xftfont;
return font;
}
function _CreatePixmapFromBuffer(int xdrawable, string buffer)
{
var fun = getxpmfun("XpmCreatePixmapFromBuffer");
if (fun == null || ! fun)
throw "Cannot create pixmap from buffer";
var intview = new ["StructView"]( [DATATYPE_STRUCT, 1, DATATYPE_INT ] );
var pixmap_return = intview.alloc();
var shapemask_return;
var attributes;
int r = fun(self.xdisplay, xdrawable, str_to_cstring(buffer),
pixmap_return, shapemask_return, attributes);
if (r != 0)
return None;
return int(intview[pixmap_return, 0]);
}
function _CreatePixmapAndShapeFromBuffer(int xdrawable, string buffer)
{
var fun = getxpmfun("XpmCreatePixmapFromBuffer");
if (fun == null || ! fun)
throw "Cannot create pixmap from buffer";
var intview = new ["StructView"]( [DATATYPE_STRUCT, 1, DATATYPE_INT ] );
var pixmap_return = intview.alloc();
var shapemask_return = intview.alloc();;
var attributes;
int r = fun(self.xdisplay, xdrawable, str_to_cstring(buffer),
pixmap_return, shapemask_return, attributes);
int pixmap = None, shape = None;
if (r == 0) {
pixmap = int(intview[pixmap_return, 0]);
shape = int(intview[shapemask_return, 0]);
}
return pixmap, shape;
}
function _SetSelectionOwner(int selection, int xwindow, int time)
{
getfun("XSetSelectionOwner")(self.xdisplay,
selection, xwindow, time);
}
function SetSelectionOwner(int selection, window, int time)
{
int xwindow = window == null ? None : window.xdrawable;
self._SetSelectionOwner(selection, xwindow, time);
}
function GetSelectionOwner(int selection)
{
return int(getfun("XGetSelectionOwner")(self.xdisplay, selection));
}
function ConvertSelection(int selection, int target, int property,
requestor, int time)
{
getfun("XConvertSelection")(self.xdisplay, selection, target,
property, requestor.xdrawable, time);
}
function ChangePropertyInt32(int xwindow,
int property, int type, int mode, int value)
{
var viewint = new ["StructView"] ( [ DATATYPE_STRUCT, 1, DATATYPE_INT ] );
var pvalue = viewint.alloc();
viewint[pvalue, 0] = value;
var fun = getfun("XChangeProperty");
fun(self.xdisplay, xwindow, property, type, 32, mode,
pvalue, 1);
}
function ChangePropertyString(int xwindow,
int property, int type, int mode, string value)
{
var pvalue = str_to_achar_utf8(value);
var fun = getfun("XChangeProperty");
fun(self.xdisplay, xwindow, property, type, 8, mode,
pvalue, elements(pvalue));
}
function ChangePropertyStringIso(int xwindow,
int property, int type, int mode, string value)
{
var pvalue = str_to_achar(value);
var fun = getfun("XChangeProperty");
fun(self.xdisplay, xwindow, property, type, 8, mode,
pvalue, elements(pvalue));
}
}
//**********************************************************************
class Color
{
var xcolor;
function Color(xcolor)
{
self.xcolor = xcolor;
}
function pixel()
{
var xcolorview = getxcolorview();
return int(xcolorview[self.xcolor, 0]);
}
}
class XftColor
{
var xftcolor;
function pixel()
{
var xftcolorview = getxftcolorview();
int pixel = xftcolorview[self.xftcolor, 0];
return pixel;
}
}
//**********************************************************************
class FontSet
{
var xfont;
function DrawString(display, drawable, int x, int y, string str)
{
var xdrawable = drawable.xdrawable;
if (xdrawable == None)
return;
var pstr = str_to_achar_utf8(str);
int len = elements(pstr);
getfun("XmbDrawString")(display.xdisplay, xdrawable,
self.xfont, drawable.getgc().xgc, x, y, pstr, len);
}
function DrawImageString(display, drawable, int x, int y, string str)
{
var xdrawable = drawable.xdrawable;
if (xdrawable == None)
return;
var pstr = str_to_achar_utf8(str);
int len = elements(pstr);
getfun("XmbDrawImageString")(display.xdisplay, xdrawable,
self.xfont, drawable.getgc().xgc, x, y, pstr, len);
}
function getHeight()
{
var view = getxfontview();
return int(view[self.xfont, 22]) + int(view[self.xfont, 23]);
}
function getTextWidth(display, string text)
{
return int(getfun("XmbTextEscapement")(self.xfont, str_to_cstring(text), bytelength(text)));
}
function getTextxOff(display, string text)
{
return self.getTextWidth(display, text);
}
}
class XftFont
{
var xftfont;
function DrawString(display, drawable, int x, int y, string str)
{
if (length(str) == 0)
return;
var xftdraw = drawable._getXftDraw();
if (xftdraw == null)
return;
var gc = drawable.getgc();
var xcolor;
var color = gc.getForeground();
if (color != null)
xcolor = color.xftcolor;
if (xcolor == null) {
color = display.ParseColor("black");
xcolor = color.xftcolor;
}
var pstr = str_to_achar_utf8(str);
int len = elements(pstr);
getxftfun("XftDrawStringUtf8")(xftdraw, xcolor, self.xftfont,
x, y, pstr, len);
}
function DrawImageString(display, drawable, int x, int y, string str)
{
if (length(str) == 0)
return;
var xftdraw = drawable._getXftDraw();
if (xftdraw == null)
return;
var pstr = str_to_achar_utf8(str);
int len = elements(pstr);
var xftfont = self.xftfont;
var fview = getxftfontview();
int ascent = fview[xftfont, 0];
var tview = getglyphinfoview();
var glyphinfo = tview.alloc();
getxftfun("XftTextExtentsUtf8")(display.xdisplay, xftfont,
pstr, len, glyphinfo);
int top = y - tview[glyphinfo, 3];
int left = x - tview[glyphinfo, 2];
int width = tview[glyphinfo, 0];
int height = tview[glyphinfo, 1];
var gc = drawable.getgc();
var xcolor;
var color = gc.getForeground();
if (color != null)
xcolor = color.xftcolor;
if (xcolor == null) {
color = display.ParseColor("black");
xcolor = color.xftcolor;
}
var xbgcolor;
var bgcolor = gc.getBackground();
if (bgcolor != null)
xbgcolor = bgcolor.xftcolor;
if (xbgcolor == null) {
bgcolor = display.ParseColor("white");
xbgcolor = bgcolor.xftcolor;
}
getxftfun("XftDrawRect")(xftdraw, xbgcolor, left, top, width, height);
getxftfun("XftDrawStringUtf8")(xftdraw, xcolor, xftfont,
x, y, pstr, len);
}
function getAscent()
{
var view = getxftfontview();
return int(view[self.xftfont, 0]);
}
function getDescent()
{
var view = getxftfontview();
return int(view[self.xftfont, 1]);
}
function getHeight()
{
var view = getxftfontview();
return int(view[self.xftfont, 2]);
}
function getTextWidth(display, string text)
{
var pstr = str_to_achar_utf8(text);
int len = elements(pstr);
var view = getglyphinfoview();
var glyphinfo = view.alloc();
getxftfun("XftTextExtentsUtf8")(display.xdisplay, self.xftfont,
pstr, len, glyphinfo);
return int(view[glyphinfo, 0]);
}
function getTextxOff(display, string text)
{
var pstr = str_to_achar_utf8(text);
int len = elements(pstr);
var view = getglyphinfoview();
var glyphinfo = view.alloc();
getxftfun("XftTextExtentsUtf8")(display.xdisplay, self.xftfont,
pstr, len, glyphinfo);
return int(view[glyphinfo, 4]);
}
}
//**********************************************************************
function DisplayName()
{
var fn = getfun("XDisplayName");
return string_from_nci(fn(null));
}
function KeysymToString(int keysym)
{
var fn = getfun("XKeysymToString");
return string_from_nci(fn(keysym));
}
function StringToKeysym(string keystring)
{
var fn = getfun("XStringToKeysym");
var pkey = str_to_cstring(keystring);
int k = fn(pkey);
return k;
}
function OpenDisplay(string displayname[optional])
{
return new Display(displayname);
}
//**************************************************************
// Event
//**************************************************************
class Event
{
var eventdata;
var anyview;
var evtype;
var evx;
var evy;
var evx_root;
var evy_root;
var evwidth;
var evheight;
var evkeycode;
var evbutton;
var evstate;
var time;
function Event(int type[optional])
{
self.eventdata = geteventpad().alloc();
self.anyview = getanyview();
self.evtype = type;
self.anyview[self.eventdata, 0] = type;
self.evx = 0;
self.evy = 0;
self.evx_root = 0;
self.evy_root = 0;
self.evwidth = 0;
self.evheight = 0;
self.evkeycode = -1;
self.evbutton = 0;
self.evstate = 0;
}
function getview()
{
var view = self.anyview;
int type = view[self.eventdata, 0];
switch (type) {
case ConfigureNotify:
view = getstructureview();
break;
case Expose:
view = getexposeview();
break;
case KeyPress:
view = getkeyview();
break;
case ButtonPress:
case ButtonRelease:
view = getbuttonview();
break;
case MotionNotify:
view = getmotionview();
break;
case FocusIn:
case FocusOut:
view = getfocusview();
break;
case MapNotify:
case UnmapNotify:
view = getmapview();
break;
case EnterNotify:
case LeaveNotify:
view = getcrossingview();
break;
case SelectionClear:
view = getselectionclearview();
break;
case SelectionRequest:
view = getselectionrequestview();
break;
case SelectionNotify:
view = getselectionview();
break;
}
return view;
}
function _get(xdisplay, fn)
{
var eventdata = self.eventdata;
fn(xdisplay, eventdata);
var view = self.anyview;
int type = view[self.eventdata, 0];
self.evtype =: type;
int x = 0, y = 0, x_root = 0, y_root = 0,
width = 0, height = 0,
keycode = -1, button = 0,
state = 0, time = 0;
switch (type) {
case ConfigureNotify:
view = getstructureview();
x = view[eventdata, 6];
y = view[eventdata, 7];
width = view[eventdata, 8];
height = view[eventdata, 9];
break;
case Expose:
view = getexposeview();
x = view[eventdata, 5];
y = view[eventdata, 6];
width = view[eventdata, 7];
height = view[eventdata, 8];
break;
case KeyPress:
view = getkeyview();
time = view[eventdata, 7];
x = view[eventdata, 8];
y = view[eventdata, 9];
x_root = view[eventdata, 10];
y_root = view[eventdata, 11];
keycode = view[eventdata, 13];
state = view[eventdata, 12];
break;
case ButtonPress:
case ButtonRelease:
view = getbuttonview();
time = view[eventdata, 7];
x = view[eventdata, 8];
y = view[eventdata, 9];
x_root = view[eventdata, 10];
y_root = view[eventdata, 11];
button = view[eventdata, 13];
state = view[eventdata, 12];
break;
case MotionNotify:
view = getmotionview();
time = view[eventdata, 7];
x = view[eventdata, 8];
y = view[eventdata, 9];
x_root = view[eventdata, 10];
y_root = view[eventdata, 11];
state = view[eventdata, 12];
break;
case FocusIn:
case FocusOut:
view = getfocusview();
break;
case EnterNotify:
case LeaveNotify:
view = getcrossingview();
time = view[eventdata, 7];
x = view[eventdata, 8];
y = view[eventdata, 9];
x_root = view[eventdata, 10];
y_root = view[eventdata, 11];
state = view[eventdata, 16];
break;
case SelectionClear:
view = getselectionclearview();
time = view[eventdata, 6];
break;
case SelectionRequest:
view = getselectionrequestview();
time = view[eventdata, 9];
break;
case SelectionNotify:
view = getselectionview();
time = view[eventdata, 8];
break;
}
self.evx =: x;
self.evy =: y;
self.evx_root =: x_root;
self.evy_root =: y_root;
self.evwidth =: width;
self.evheight =: height;
self.evkeycode =: keycode;
self.evbutton =: button;
self.evstate =: state;
self.time = time;
}
function type()
{
return int(self.evtype);
}
function serial()
{
int t = self.anyview[self.eventdata, 1];
return t;
}
function window()
{
int t = self.anyview[self.eventdata, 4];
return t;
}
function time()
{
return int(self.time);
}
function x()
{
return int(self.evx);
}
function y()
{
return int(self.evy);
}
function x_root()
{
return int(self.evx_root);
}
function y_root()
{
return int(self.evy_root);
}
function width()
{
return int(self.evwidth);
}
function height()
{
return int(self.evheight);
}
function keycode()
{
return int(self.evkeycode);
}
function keyname()
{
int keycode = self.evkeycode;
string key;
if (keycode >= 0) {
var xdisplay = self.anyview[self.eventdata, 3];
int keysym = getfun("XKeycodeToKeysym")(xdisplay, keycode, 0);
key = KeysymToString(keysym);
}
return key;
}
function button()
{
return int(self.evbutton);
}
function state()
{
return int(self.evstate);
}
function detail()
{
int detail = 0;
int type = self.evtype;
var view;
switch (type) {
case EnterNotify:
case LeaveNotify:
view = getcrossingview();
detail = view[self.eventdata, 13];
break;
case FocusIn:
case FocusOut:
view = getfocusview();
detail = view[self.eventdata, 6];
break;
}
return detail;
}
function requestor()
{
int req = None;
int type = self.evtype;
var view;
int pos;
switch (type) {
case SelectionRequest:
view = getselectionrequestview();
pos = 5;
break;
case SelectionNotify:
view = getselectionview();
pos = 4;
break;
}
if (view != null)
req = view[self.eventdata, pos];
return req;
}
function selection()
{
int req = None;
int type = self.evtype;
var view;
int pos;
switch (type) {
case SelectionClear:
view = getselectionclearview();
pos = 5;
break;
case SelectionRequest:
view = getselectionrequestview();
pos = 6;
break;
case SelectionNotify:
view = getselectionview();
pos = 5;
break;
}
if (view != null)
req = view[self.eventdata, pos];
return req;
}
function target()
{
int req = None;
int type = self.evtype;
var view;
int pos;
switch (type) {
case SelectionRequest:
view = getselectionrequestview();
pos = 7;
break;
case SelectionNotify:
view = getselectionview();
pos = 6;
break;
}
if (view != null)
req = view[self.eventdata, pos];
return req;
}
function property()
{
int req = None;
int type = self.evtype;
var view;
int pos;
switch (type) {
case SelectionRequest:
view = getselectionrequestview();
pos = 8;
break;
case SelectionNotify:
view = getselectionview();
pos = 7;
break;
}
if (view != null)
req = view[self.eventdata, pos];
return req;