forked from shabble/mouseterm
-
Notifications
You must be signed in to change notification settings - Fork 4
/
MTView.m
796 lines (715 loc) · 24.1 KB
/
MTView.m
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
#import <Cocoa/Cocoa.h>
#import <math.h>
#import "MTProfile.h"
#import "MTShell.h"
#import "MTView.h"
#import "Mouse.h"
#import "Terminal.h"
#import "MouseTerm.h"
@implementation NSObject (TTLogicalScreen)
- (NSValue*) MouseTerm_initVars2
{
NSValue* ptr = [NSValue valueWithPointer: self];
if ([MouseTerm_ivars objectForKey: ptr] == nil)
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[MouseTerm_ivars setObject: dict forKey: ptr];
[dict setObject: [NSNumber numberWithInt: NO]
forKey: @"emojiFix"];
}
return ptr;
}
- (void) MouseTerm_setNaturalEmojiWidth: (BOOL) emojiFix
{
NSValue* ptr = [NSValue valueWithPointer: self];
if ([MouseTerm_ivars objectForKey: ptr] == nil)
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
[MouseTerm_ivars setObject: dict forKey: ptr];
[dict setObject: [NSNumber numberWithInt: emojiFix]
forKey: @"emojiFix"];
} else {
[[MouseTerm_ivars objectForKey: ptr]
setObject: [NSNumber numberWithBool: emojiFix]
forKey: @"emojiFix"];
}
}
- (BOOL) MouseTerm_getNaturalEmojiWidth
{
NSValue* ptr = [NSValue valueWithPointer: self];
if ([MouseTerm_ivars objectForKey: ptr] == nil)
{
return NO;
}
return [(NSNumber*) [[MouseTerm_ivars objectForKey: ptr]
objectForKey: @"emojiFix"] boolValue];
}
- (unsigned long long)MouseTerm_logicalWidthForCharacter:(int)code
{
if ((code & 0x1f0000) == 0x10000)
if ([self MouseTerm_getNaturalEmojiWidth])
return 2;
return [self MouseTerm_logicalWidthForCharacter:code];
}
- (unsigned long long)MouseTerm_displayWidthForCharacter:(int)code
{
if ((code & 0x1f0000) == 0x10000)
if ([self MouseTerm_getNaturalEmojiWidth])
return 2;
return [self MouseTerm_displayWidthForCharacter:code];
}
@end
@implementation NSView (MTView)
static BOOL mouseEnabled = YES;
static BOOL base64CopyEnabled = YES;
static BOOL base64PasteEnabled = YES;
- (id) MouseTerm_colorForANSIColor:(unsigned int)index;
{
id colour = nil;
MTShell *shell = [[(TTView*)self controller] shell];
NSMutableDictionary *palette = [(MTShell*)shell MouseTerm_getPalette];
int n;
if (palette) {
if (index < 17) {
n = index - 1;
} else if (index < 1000) {
n = index;
} else {
n = index - 1000;
}
colour = [palette objectForKey:[NSNumber numberWithInt: n]];
if (colour) {
return colour;
}
}
return [self MouseTerm_colorForANSIColor: index];
}
- (id) MouseTerm_colorForANSIColor:(unsigned int)index adjustedRelativeToColor:(id)bgColor;
{
id colour = nil;
MTShell *shell = [[(TTView*) self controller] shell];
NSMutableDictionary *palette = [(MTShell*)shell MouseTerm_getPalette];
int n;
if (palette) {
if (index == 0) {
if (bgColor) {
n = -1;
} else {
n = -3;
}
} else if (index < 17) {
n = index - 1;
} else if (index < 1000) {
n = index;
} else {
n = index - 1000;
}
colour = [palette objectForKey:[NSNumber numberWithInt: n]];
}
if (colour)
{
colour = [(TTView *)self adjustedColorWithColor: colour
withBackgroundColor: bgColor
force: YES];
return colour;
}
colour = [self MouseTerm_colorForANSIColor: index
adjustedRelativeToColor: bgColor];
return colour;
}
- (id) MouseTerm_colorForExtendedANSIColor:(unsigned long long)index adjustedRelativeToColor:(id)bgColor withProfile:(id)profile
{
id colour = nil;
MTShell *shell = [[(TTView*) self controller] shell];
NSMutableDictionary *palette = [(MTShell*)shell MouseTerm_getPalette];
int n;
if (palette) {
if (index < 17) {
n = index - 1;
} else if (index < 1000) {
n = index;
} else {
n = index - 1000;
}
colour = [palette objectForKey: [NSNumber numberWithInt: n]];
if (colour)
{
colour = [(TTView *)self adjustedColorWithColor: colour
withBackgroundColor: bgColor
force: YES];
return colour;
}
}
colour = [self MouseTerm_colorForExtendedANSIColor: index
adjustedRelativeToColor: bgColor
withProfile: profile];
return colour;
}
- (NSData*) MouseTerm_codeForX: (unsigned int) x
Y: (unsigned int) y
modifier: (char) modflag
button: (MouseButton) button
motion: (BOOL) motion
release: (BOOL) release
{
char cb = button;
int buttonState = 0;
int state;
MTShell* shell = [[(TTView*) self controller] shell];
MouseProtocol mouseProtocol = [shell MouseTerm_getMouseProtocol];
MouseMode mode = [shell MouseTerm_getMouseMode];
unsigned int len = 0;
const size_t BUFFER_LENGTH = 256;
char buf[BUFFER_LENGTH];
switch (mode) {
case DEC_LOCATOR_ONESHOT_MODE:
case DEC_LOCATOR_MODE:
state = [shell MouseTerm_getMouseState];
if (state & 1 << MOUSE_BUTTON1) buttonState |= 4;
if (state & 1 << MOUSE_BUTTON3) buttonState |= 2;
if (state & 1 << MOUSE_BUTTON2) buttonState |= 1;
if (motion) {
cb = 10;
} else {
cb = button * 2 + 2 + (release ? 1: 0);
}
snprintf(buf, BUFFER_LENGTH, "\e[%d;%d;%d;%d;%d&w", cb, buttonState, y, x, 0);
len = strlen(buf);
if (mode == DEC_LOCATOR_ONESHOT_MODE)
[shell MouseTerm_setMouseMode: NO_MODE];
break;
default:
if (modflag & NSShiftKeyMask) cb |= 4;
if (modflag & NSAlternateKeyMask) cb |= 8;
if (modflag & NSControlKeyMask) cb |= 16;
if (motion) cb += 32;
switch (mouseProtocol) {
case URXVT_PROTOCOL:
if (release)
cb |= MOUSE_RELEASE;
cb += 32; // base offset +32 (to make it printable)
snprintf(buf, BUFFER_LENGTH, "\e[%d;%d;%dM", cb, x, y);
len = strlen(buf);
break;
case SGR_PROTOCOL:
if (release) // release
snprintf(buf, BUFFER_LENGTH, "\e[<%d;%d;%dm", cb, x, y);
else
snprintf(buf, BUFFER_LENGTH, "\e[<%d;%d;%dM", cb, x, y);
len = strlen(buf);
break;
case NORMAL_PROTOCOL:
default:
// add base offset +32 (to make it printable)
cb += 32;
x += 32;
y += 32;
if (release)
cb |= MOUSE_RELEASE;
x = MIN(x, 255);
y = MIN(y, 255);
len = MOUSE_RESPONSE_LEN;
snprintf(buf, len + 1, MOUSE_RESPONSE, cb, x, y);
break;
}
break;
}
return [NSData dataWithBytes: buf length: len];
}
+ (void) MouseTerm_setMouseEnabled: (BOOL) value
{
NSLog(@"[MouseTerm] INFO: setMouseEnabled");
mouseEnabled = value;
}
+ (BOOL) MouseTerm_getMouseEnabled
{
return mouseEnabled;
}
+ (void) MouseTerm_setBase64CopyEnabled: (BOOL) value
{
base64CopyEnabled = value;
}
+ (BOOL) MouseTerm_getBase64CopyEnabled
{
return base64CopyEnabled;
}
+ (void) MouseTerm_setBase64PasteEnabled: (BOOL) value
{
base64PasteEnabled = value;
}
+ (BOOL) MouseTerm_getBase64PasteEnabled
{
return base64PasteEnabled;
}
- (NSScroller*) MouseTerm_scroller
{
if ([self respondsToSelector: @selector(pane)])
return [[(TTView*) self pane] scroller];
else
return [(TTTabController*) [(TTView*) self controller] scroller];
}
- (BOOL) MouseTerm_shouldIgnore: (NSEvent*) event button: (MouseButton) button
{
if (![NSView MouseTerm_getMouseEnabled])
return YES;
// Don't handle if alt/option/control is pressed
if ([event modifierFlags] & (NSAlternateKeyMask | NSControlKeyMask))
return YES;
TTLogicalScreen* screen = [(TTView*) self logicalScreen];
// Don't handle if the scroller isn't at the bottom
linecount_t scrollback =
(linecount_t) [screen lineCount] -
(linecount_t) [(TTView*) self rowCount];
if (scrollback > 0 && [[self MouseTerm_scroller] floatValue] < 1.0)
return YES;
// Don't handle if a profile option is disabled
MTProfile* profile = [(TTTabController*) [(TTView*) self controller]
profile];
if (![profile MouseTerm_buttonEnabled: button])
return YES;
return NO;
}
- (BOOL) MouseTerm_shouldIgnoreDown: (NSEvent*) event
button: (MouseButton) button
{
if ([self MouseTerm_shouldIgnore: event button: button])
return YES;
MTShell* shell = [[(TTView*) self controller] shell];
if (![shell MouseTerm_getMouseState] & 1 << button)
return YES;
return NO;
}
- (BOOL) MouseTerm_shouldIgnoreMoved: (NSEvent*) event
{
// check if the mouse location is in the bounds of window.
NSPoint location = [event locationInWindow];
NSRect bounds = [(NSView*) self bounds];
if (NSPointInRect(location, bounds))
return NO;
return YES;
}
- (Position) MouseTerm_currentPosition: (NSEvent*) event
{
linecount_t scrollback =
(linecount_t) [[(TTView*) self logicalScreen] lineCount] -
(linecount_t) [(TTView*) self rowCount];
NSPoint viewloc = [self convertPoint: [event locationInWindow]
fromView: nil];
Position pos = [(TTView*) self displayPositionForPoint: viewloc];
// The above method returns the position *including* scrollback,
// so we have to compensate for that.
pos.y -= scrollback;
pos.y += 1; // origin offset +1
// pos.x may not indicate correct coordinate value if the tail
// cells of line buffer are empty, so we calculate it from the cell size.
CGSize size = [(TTView*) self cellSize];
pos.x = (linecount_t)round(viewloc.x / size.width);
// treat negative position value as 1.
pos.x = MAX(1, (int)pos.x);
pos.y = MAX(1, (int)pos.y);
return pos;
}
- (BOOL) MouseTerm_buttonDown: (NSEvent*) event button: (MouseButton) button
{
NSData *data;
if ([self MouseTerm_shouldIgnore: event button: button])
goto ignored;
MTShell* shell = [[(TTView*) self controller] shell];
switch ([shell MouseTerm_getMouseMode])
{
case NO_MODE:
case HILITE_MODE:
goto ignored;
case DEC_LOCATOR_MODE:
case DEC_LOCATOR_ONESHOT_MODE:
if (!([shell MouseTerm_getEventFilter] & BUTTONDOWN_EVENT)) {
[shell MouseTerm_setMouseState: [shell MouseTerm_getMouseState] | 1 << button];
goto handled;
}
// pass through
case NORMAL_MODE:
case BUTTON_MODE:
case ALL_MODE:
[shell MouseTerm_setMouseState: [shell MouseTerm_getMouseState] | 1 << button];
{
// get mouse position, the origin coodinate is (1, 1).
Position pos = [self MouseTerm_currentPosition: event];
[shell MouseTerm_cachePosition: &pos];
data = [self MouseTerm_codeForX: pos.x
Y: pos.y
modifier: [event modifierFlags]
button: button
motion: NO
release: NO];
[(TTShell*) shell writeData: data];
}
goto handled;
}
handled:
[(TTView*) self clearTextSelection];
return YES;
ignored:
return NO;
}
- (BOOL) MouseTerm_buttonMoved: (NSEvent*) event
{
NSData* data;
if ([self MouseTerm_shouldIgnoreMoved: event])
goto ignored;
MTShell* shell = [[(TTView*) self controller] shell];
switch ([shell MouseTerm_getMouseMode])
{
case NO_MODE:
goto ignored;
case NORMAL_MODE:
case HILITE_MODE:
case BUTTON_MODE:
goto ignored;
case DEC_LOCATOR_MODE:
case DEC_LOCATOR_ONESHOT_MODE:
{
NSValue *value = [shell MouseTerm_getFilterRectangle];
int x;
int y;
if (value) {
int filterRect[4];
[value getValue: &filterRect];
if ([shell MouseTerm_getCoordinateType] == PIXEL_COORDINATE) {
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
x = point.x;
y = [self frame].size.height - point.y;
} else {
Position point = [self MouseTerm_currentPosition: event];
x = point.x;
y = point.y;
}
if (y >= filterRect[0] && x >= filterRect[1] && y <= filterRect[2] && x <= filterRect[3])
goto handled;
[shell MouseTerm_setFilterRectangle: nil];
data = [self MouseTerm_codeForX: x Y: y modifier: 0 button: 0 motion: YES release: NO];
[(TTShell*) shell writeData: data];
}
}
goto handled;
case ALL_MODE:
{
// get mouse position, the origin coodinate is (1, 1).
Position pos = [self MouseTerm_currentPosition: event];
if ([shell MouseTerm_positionIsChanged: &pos]) {
[shell MouseTerm_cachePosition: &pos];
data = [self MouseTerm_codeForX: pos.x
Y: pos.y
modifier: [event modifierFlags]
button: MOUSE_RELEASE
motion: YES
release: NO];
[(TTShell*) shell writeData: data];
}
}
goto handled;
}
handled:
[(TTView*) self clearTextSelection];
return YES;
ignored:
return NO;
}
- (BOOL) MouseTerm_buttonDragged: (NSEvent*) event button: (MouseButton) button
{
NSData* data;
if ([self MouseTerm_shouldIgnoreDown: event button: button])
goto ignored;
MTShell* shell = [[(TTView*) self controller] shell];
switch ([shell MouseTerm_getMouseMode])
{
case NO_MODE:
goto ignored;
case NORMAL_MODE:
case HILITE_MODE:
goto handled;
case DEC_LOCATOR_MODE:
case DEC_LOCATOR_ONESHOT_MODE:
{
NSValue *value = [shell MouseTerm_getFilterRectangle];
int x;
int y;
if (value) {
int filterRect[4];
[value getValue: &filterRect];
if ([shell MouseTerm_getCoordinateType] == PIXEL_COORDINATE) {
NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil];
x = point.x;
y = [self frame].size.height - point.y;
} else {
Position point = [self MouseTerm_currentPosition: event];
x = point.x;
y = point.y;
}
if (y >= filterRect[0] && x >= filterRect[1] && y <= filterRect[2] && x <= filterRect[3])
goto handled;
[shell MouseTerm_setFilterRectangle: nil];
data = [self MouseTerm_codeForX: x Y: y modifier: 0 button: 0 motion: YES release: NO];
[(TTShell*) shell writeData: data];
}
}
goto handled;
case BUTTON_MODE:
case ALL_MODE:
{
// get mouse position, the origin coodinate is (1, 1).
Position pos = [self MouseTerm_currentPosition: event];
if ([shell MouseTerm_positionIsChanged: &pos]) {
[shell MouseTerm_cachePosition: &pos];
data = [self MouseTerm_codeForX: pos.x
Y: pos.y
modifier: [event modifierFlags]
button: button
motion: YES
release: NO];
[(TTShell*) shell writeData: data];
}
}
goto handled;
}
handled:
[(TTView*) self clearTextSelection];
return YES;
ignored:
return NO;
}
- (BOOL) MouseTerm_buttonUp: (NSEvent*) event button: (MouseButton) button
{
NSData *data;
if ([self MouseTerm_shouldIgnoreDown: event button: button])
goto ignored;
MTShell* shell = [[(TTView*) self controller] shell];
switch ([shell MouseTerm_getMouseMode])
{
case NO_MODE:
case HILITE_MODE:
goto ignored;
case DEC_LOCATOR_MODE:
case DEC_LOCATOR_ONESHOT_MODE:
if (!([shell MouseTerm_getEventFilter] & BUTTONUP_EVENT)) {
[shell MouseTerm_setMouseState: [shell MouseTerm_getMouseState] & ~(1 << button)];
goto handled;
}
// pass through
case NORMAL_MODE:
case BUTTON_MODE:
case ALL_MODE:
[shell MouseTerm_setMouseState: [shell MouseTerm_getMouseState] & ~(1 << button)];
{
// get mouse position, the origin coodinate is (1, 1).
Position pos = [self MouseTerm_currentPosition: event];
[shell MouseTerm_cachePosition: &pos];
data = [self MouseTerm_codeForX: pos.x
Y: pos.y
modifier: [event modifierFlags]
button: button
motion: NO
release: YES];
[(TTShell*) shell writeData: data];
}
goto handled;
}
handled:
[(TTView*) self clearTextSelection];
return YES;
ignored:
return NO;
}
- (void) MouseTerm_mouseDown: (NSEvent*) event
{
MouseButton button;
if ([event modifierFlags] & NSCommandKeyMask)
button = MOUSE_BUTTON3;
else
button = MOUSE_BUTTON1;
if (![self MouseTerm_buttonDown: event button: button])
[self MouseTerm_mouseDown: event];
}
- (void) MouseTerm_mouseMoved: (NSEvent*) event
{
[self MouseTerm_buttonMoved: event];
}
- (void) MouseTerm_mouseDragged: (NSEvent*) event
{
MouseButton button;
if ([event modifierFlags] & NSCommandKeyMask)
button = MOUSE_BUTTON3;
else
button = MOUSE_BUTTON1;
if (![self MouseTerm_buttonDragged: event button: button])
[self MouseTerm_mouseDragged: event];
}
- (void) MouseTerm_mouseUp: (NSEvent*) event
{
MouseButton button;
if ([event modifierFlags] & NSCommandKeyMask)
button = MOUSE_BUTTON3;
else
button = MOUSE_BUTTON1;
if (![self MouseTerm_buttonUp: event button: button])
[self MouseTerm_mouseUp: event];
}
- (void) MouseTerm_rightMouseDown: (NSEvent*) event
{
if (![self MouseTerm_buttonDown: event button: MOUSE_BUTTON2])
[self MouseTerm_rightMouseDown: event];
}
- (void) MouseTerm_rightMouseDragged: (NSEvent*) event
{
if (![self MouseTerm_buttonDragged: event button: MOUSE_BUTTON2])
[self MouseTerm_rightMouseDragged: event];
}
- (void) MouseTerm_rightMouseUp: (NSEvent*) event
{
if (![self MouseTerm_buttonUp: event button: MOUSE_BUTTON2])
[self MouseTerm_rightMouseUp: event];
}
- (void) MouseTerm_otherMouseDown: (NSEvent*) event
{
if (![self MouseTerm_buttonDown: event button: MOUSE_BUTTON3])
[self MouseTerm_otherMouseDown: event];
}
- (void) MouseTerm_otherMouseDragged: (NSEvent*) event
{
if (![self MouseTerm_buttonDragged: event button: MOUSE_BUTTON3])
[self MouseTerm_otherMouseDragged: event];
}
- (void) MouseTerm_otherMouseUp: (NSEvent*) event
{
if (![self MouseTerm_buttonUp: event button: MOUSE_BUTTON3])
[self MouseTerm_otherMouseUp: event];
}
// Intercepts all scroll wheel movements (one wheel "tick" at a time)
- (void) MouseTerm_scrollWheel: (NSEvent*) event
{
NSData* data;
long i;
long lines;
double delta;
MTProfile* profile;
MouseButton button;
if ([self MouseTerm_shouldIgnore: event button: MOUSE_WHEEL_UP])
goto ignored;
TTLogicalScreen* screen = [(TTView*) self logicalScreen];
MTShell* shell = [[(TTView*) self controller] shell];
switch ([shell MouseTerm_getMouseMode])
{
case NO_MODE:
profile = [(TTTabController*) [(TTView*) self controller] profile];
if ([NSView MouseTerm_getMouseEnabled] &&
[profile MouseTerm_emulationEnabled] &&
[screen isAlternateScreenActive] &&
[shell MouseTerm_getAppCursorMode])
{
// Calculate how many lines to scroll by (takes acceleration
// into account)
// deltaY returns CGFloat, which can be float or double
// depending on the architecture. Upcasting floats to doubles
// seems like an easier compromise than detecting what the
// type really is.
delta = [event deltaY];
// Trackpads seem to return a lot of 0.0 events, which
// shouldn't trigger scrolling anyway.
if (delta == 0.0)
goto handled;
else if (delta < 0.0)
{
delta = fabs(delta);
data = [NSData dataWithBytes: DOWN_ARROW_APP
length: ARROW_LEN];
}
else
{
data = [NSData dataWithBytes: UP_ARROW_APP
length: ARROW_LEN];
}
linecount_t i;
linecount_t lines = lround(delta) + 1;
for (i = 0; i < lines; ++i)
[(TTShell*) shell writeData: data];
goto handled;
}
else
goto ignored;
// FIXME: Unhandled at the moment
case HILITE_MODE:
goto ignored;
case NORMAL_MODE:
case BUTTON_MODE:
case ALL_MODE:
delta = [event deltaY];
if (delta == 0.0)
goto handled;
else if (delta < 0.0)
{
delta = fabs(delta);
button = MOUSE_WHEEL_DOWN;
}
else
button = MOUSE_WHEEL_UP;
{
// get mouse position, the origin coodinate is (1, 1).
Position pos = [self MouseTerm_currentPosition: event];
data = [self MouseTerm_codeForX: pos.x
Y: pos.y
modifier: [event modifierFlags]
button: button
motion: NO
release: NO];
lines = lround(delta) + 1;
for (i = 0; i < lines; ++i)
[(TTShell*) shell writeData: data];
}
goto handled;
}
handled:
[(TTView*) self clearTextSelection];
return;
ignored:
[self MouseTerm_scrollWheel: event];
}
- (BOOL) MouseTerm_acceptsFirstResponder
{
return YES;
}
- (BOOL) MouseTerm_windowDidBecomeKey: (id) arg1
{
NSData* data = [NSData dataWithBytes: "\033[I" length: 3];
MTShell* shell = [[(TTView*) self controller] shell];
if ([shell MouseTerm_getFocusMode]) {
[(TTShell*) shell writeData: data];
}
return YES;
}
- (BOOL) MouseTerm_windowDidResignKey: (id) arg1
{
NSData* data = [NSData dataWithBytes: "\033[O" length: 3];
MTShell* shell = [[(TTView*) self controller] shell];
if ([shell MouseTerm_getFocusMode]) {
[(TTShell*) shell writeData: data];
}
return YES;
}
- (BOOL) MouseTerm_becomeFirstResponder
{
NSData* data = [NSData dataWithBytes: "\033[I" length: 3];
MTShell* shell = [[(TTView*) self controller] shell];
if ([shell MouseTerm_getFocusMode]) {
[(TTShell*) shell writeData: data];
}
return YES;
}
- (BOOL) MouseTerm_resignFirstResponder
{
NSData* data = [NSData dataWithBytes: "\033[O" length: 3];
MTShell* shell = [[(TTView*) self controller] shell];
if ([shell MouseTerm_getFocusMode]) {
[(TTShell*) shell writeData: data];
}
return YES;
}
@end