-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabtouch.h
93 lines (93 loc) · 5.51 KB
/
tabtouch.h
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
fprintf(stdout, " var touch = { enabled: false, down: false\n");
fprintf(stdout, " , lasttouchcount: 0\n");
fprintf(stdout, " , sx: 0, sy: 0, ex: 0, ey: 0\n");
fprintf(stdout, " , dx: 0, dy: 0, mx: 0, my: 0\n");
fprintf(stdout, " , minmx: 50, minmy: 50 }\n");
fprintf(stdout, " function touchenable() {\n");
fprintf(stdout, " if ('ontouchstart' in document.documentElement) {\n");
fprintf(stdout, " document.addEventListener('touchstart', touchdown, false);\n");
fprintf(stdout, " document.addEventListener('touchmove', touchup, false);\n");
fprintf(stdout, " touch.enabled = true;\n");
fprintf(stdout, " }\n");
fprintf(stdout, " }\n");
fprintf(stdout, " function touchdown(evt) {\n");
fprintf(stdout, " if (!copying && !pasting) {\n");
fprintf(stdout, " evt.stopPropagation();\n");
fprintf(stdout, " evt.preventDefault();\n");
fprintf(stdout, " }\n");
fprintf(stdout, " var touchcount = evt.touches.length;\n");
fprintf(stdout, " var lasttc = touch.lasttouchcount;\n");
fprintf(stdout, " if (touchcount > 0) {\n");
fprintf(stdout, " touch.sx = evt.touches[0].pageX;\n");
fprintf(stdout, " touch.sy = evt.touches[0].pageY;\n");
fprintf(stdout, " touch.down = true;\n");
fprintf(stdout, " }\n");
fprintf(stdout, " }\n");
fprintf(stdout, " function touchup(evt) {\n");
fprintf(stdout, " evt.stopPropagation();\n");
fprintf(stdout, " evt.preventDefault();\n");
// fprintf(stdout, " evt.stopPropagation();\n");
// fprintf(stdout, " evt.stopImmediatePropagation();\n");
fprintf(stdout, " if (!touch.down) { return; }\n");
fprintf(stdout, " var touchcount = evt.touches.length;\n");
fprintf(stdout, " var touchshift = (touchcount == 2);\n");
fprintf(stdout, " var touchmeta = (touchcount == 3);\n");
fprintf(stdout, " var lasttc = touch.lasttouchcount;\n");
fprintf(stdout, " touch.lasttouchcount = touchcount;\n");
fprintf(stdout, " touch.ex = evt.touches[0].pageX;\n");
fprintf(stdout, " touch.ey = evt.touches[0].pageY;\n");
fprintf(stdout, " touch.dx = touch.ex - touch.sx;\n");
fprintf(stdout, " touch.dy = touch.ey - touch.sy;\n");
fprintf(stdout, " touch.mx = Math.abs(touch.dx);\n");
fprintf(stdout, " touch.my = Math.abs(touch.dy);\n");
fprintf(stdout, " var event = { ctrlKey: false, altKey: false\n");
fprintf(stdout, " , shiftKey: touchshift, keyCode: 0\n");
fprintf(stdout, " , preventDefault: function() { } }\n");
fprintf(stdout, " if (touch.mx > touch.minmx) {\n");
fprintf(stdout, " var touchdir = (touch.dx < 0) ? 'l' : 'r';\n");
fprintf(stdout, " var touchcode = (touch.dx < 0) ? 37 : 39;\n");
fprintf(stdout, " var touchkey = false;\n");
fprintf(stdout, " if (touchshift) {\n");
fprintf(stdout, " if (touchdir == 'l')\n");
fprintf(stdout, " { touchcode = 9; touchkey = true; }\n");
fprintf(stdout, " if (touchdir == 'r')\n");
fprintf(stdout, " { touchcode = 96; touchkey = true; }\n");
fprintf(stdout, " } else if (touchmeta) {\n");
fprintf(stdout, " if (touchdir == 'l')\n");
fprintf(stdout, " { wispgoto('tsol'); }\n");
fprintf(stdout, " if (touchdir == 'r')\n");
fprintf(stdout, " { wispgoto('teol'); }\n");
fprintf(stdout, " } else { touchkey = true; }\n");
fprintf(stdout, " if (touchkey) {\n");
fprintf(stdout, " event.keyCode = touchcode;\n");
fprintf(stdout, " touch.down = false;\n");
fprintf(stdout, " window.onkeydown(event);\n");
fprintf(stdout, " window.onkeyup(event);\n");
fprintf(stdout, " }\n");
fprintf(stdout, " } else if (touch.my > touch.minmy) {\n");
// fprintf(stdout, " if (touchshift) {\n");
// fprintf(stdout, " if (wisplinelen() == 0) {\n");
// fprintf(stdout, " { bodydragtoggle(); }\n");
// fprintf(stdout, " else if (touchshift && touch.dy < -100)\n");
// fprintf(stdout, " { pastefocus(); }\n");
// fprintf(stdout, " else if (touchshift && touch.dy > 100)\n");
fprintf(stdout, " var touchdir = (touch.dy < 0) ? 'u' : 'd';\n");
fprintf(stdout, " var touchcode = (touch.dy < 0) ? 38 : 40;\n");
fprintf(stdout, " if (touchshift) {\n"); // && touch.dy < -200)\n");
fprintf(stdout, " if (touchdir == 'u')\n");
fprintf(stdout, " { bodydragtoggle(); }\n");
fprintf(stdout, " if (touchdir == 'd')\n");
fprintf(stdout, " { wispopen('h'); }\n");
fprintf(stdout, " } else if (touchmeta) {\n");
fprintf(stdout, " if (touchdir == 'u')\n");
fprintf(stdout, " { copyfocus(); }\n");
fprintf(stdout, " if (touchdir == 'd')\n");
fprintf(stdout, " { pastefocus(); }\n");
fprintf(stdout, " } else {\n");
fprintf(stdout, " event.keyCode = touchcode;\n");
fprintf(stdout, " window.onkeydown(event);\n");
fprintf(stdout, " window.onkeyup(event);\n");
fprintf(stdout, " }\n");
fprintf(stdout, " touch.down = false;\n");
fprintf(stdout, " }\n");
fprintf(stdout, " }\n");