Skip to content

Commit cab4040

Browse files
authored
Merge pull request #405 from osheroff/master
Fix problems with non-native fullscreen and mac 10.12
2 parents 4dba9d1 + 4663f06 commit cab4040

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

src/MacVim/MMCoreTextView.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
CGGlyph *glyphs;
3939
CGPoint *positions;
4040
NSMutableArray *fontCache;
41-
41+
CGLayerRef layer;
42+
CGContextRef layerContext;
4243
// These are used in MMCoreTextView+ToolTip.m
4344
id trackingRectOwner_; // (not retained)
4445
void *trackingRectUserData_;

src/MacVim/MMCoreTextView.m

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,19 @@ - (void)drawRect:(NSRect)rect
592592
[self batchDrawData:data];
593593

594594
[drawData removeAllObjects];
595+
596+
CGLayerRef l = [self getLayer];
597+
598+
/* during a live resize, we will have around a stale layer until the
599+
* refresh messages travel back from the vim process. we push the old
600+
* layer in at an offset to get rid of jitter due to lines changing position. */
601+
602+
CGSize layerSize = CGLayerGetSize(l);
603+
CGSize frameSize = [self frame].size;
604+
NSRect drawRect = NSMakeRect(0, frameSize.height - layerSize.height, layerSize.width, layerSize.height);
605+
606+
CGContextDrawLayerInRect([context graphicsPort], drawRect, l);
607+
595608
}
596609

597610
- (void)performBatchDrawWithData:(NSData *)data
@@ -605,6 +618,33 @@ - (void)performBatchDrawWithData:(NSData *)data
605618
[self display];
606619
}
607620

621+
- (void)releaseLayer
622+
{
623+
if (layer) {
624+
CGLayerRelease(layer);
625+
layer = nil;
626+
layerContext = nil;
627+
}
628+
}
629+
- (CGLayerRef)getLayer
630+
{
631+
if (!layer) {
632+
NSGraphicsContext *context = [NSGraphicsContext currentContext];
633+
NSRect frame = [self frame];
634+
layer = CGLayerCreateWithContext([context graphicsPort], frame.size, NULL);
635+
}
636+
return layer;
637+
}
638+
639+
- (CGContextRef)getLayerContext
640+
{
641+
if (!layerContext)
642+
layerContext = CGLayerGetContext([self getLayer]);
643+
644+
return layerContext;
645+
}
646+
647+
608648
- (NSSize)constrainRows:(int *)rows columns:(int *)cols toSize:(NSSize)size
609649
{
610650
// TODO:
@@ -852,7 +892,7 @@ - (void)batchDrawData:(NSData *)data
852892
const void *end = bytes + [data length];
853893

854894
#if MM_DEBUG_DRAWING
855-
ASLogNotice(@"====> BEGIN %s", _cmd);
895+
ASLogNotice(@"====> BEGIN");
856896
#endif
857897
// TODO: Sanity check input
858898

@@ -908,10 +948,13 @@ - (void)batchDrawData:(NSData *)data
908948
column:col
909949
numRows:height
910950
numColumns:width];
911-
[signImg drawInRect:r
912-
fromRect:NSZeroRect
913-
operation:NSCompositingOperationSourceOver
914-
fraction:1.0];
951+
952+
CGContextRef context = [self getLayerContext];
953+
CGImageRef cgImage = [signImg CGImageForProposedRect:&r
954+
context:nil
955+
hints:nil];
956+
957+
CGContextDrawImage(context, r, cgImage);
915958
} else if (DrawStringDrawType == type) {
916959
int bg = *((int*)bytes); bytes += sizeof(int);
917960
int fg = *((int*)bytes); bytes += sizeof(int);
@@ -1013,7 +1056,7 @@ - (void)batchDrawData:(NSData *)data
10131056
}
10141057

10151058
#if MM_DEBUG_DRAWING
1016-
ASLogNotice(@"<==== END %s", _cmd);
1059+
ASLogNotice(@"<==== END");
10171060
#endif
10181061
}
10191062

@@ -1294,7 +1337,7 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
12941337
withFlags:(int)flags foregroundColor:(int)fg
12951338
backgroundColor:(int)bg specialColor:(int)sp
12961339
{
1297-
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
1340+
CGContextRef context = [self getLayerContext];
12981341
NSRect frame = [self bounds];
12991342
float x = col*cellSize.width + insetSize.width;
13001343
float y = frame.size.height - insetSize.height - (1+row)*cellSize.height;
@@ -1412,8 +1455,16 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
14121455

14131456
- (void)scrollRect:(NSRect)rect lineCount:(int)count
14141457
{
1415-
NSSize delta={0, -count * cellSize.height};
1416-
[self scrollRect:rect by:delta];
1458+
CGContextRef context = [self getLayerContext];
1459+
int yOffset = count * cellSize.height;
1460+
NSRect clipRect = rect;
1461+
clipRect.origin.y -= yOffset;
1462+
1463+
/* draw self on top of self, offset so as to "scroll" lines vertically. */
1464+
CGContextSaveGState(context);
1465+
CGContextClipToRect(context, clipRect);
1466+
CGContextDrawLayerAtPoint(context, CGPointMake(0, -yOffset), [self getLayer]);
1467+
CGContextRestoreGState(context);
14171468
}
14181469

14191470
- (void)deleteLinesFromRow:(int)row lineCount:(int)count
@@ -1455,7 +1506,7 @@ - (void)insertLinesAtRow:(int)row lineCount:(int)count
14551506
- (void)clearBlockFromRow:(int)row1 column:(int)col1 toRow:(int)row2
14561507
column:(int)col2 color:(int)color
14571508
{
1458-
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
1509+
CGContextRef context = [self getLayerContext];
14591510
NSRect rect = [self rectFromRow:row1 column:col1 toRow:row2 column:col2];
14601511

14611512
CGContextSetRGBFillColor(context, RED(color), GREEN(color), BLUE(color),
@@ -1468,7 +1519,8 @@ - (void)clearBlockFromRow:(int)row1 column:(int)col1 toRow:(int)row2
14681519

14691520
- (void)clearAll
14701521
{
1471-
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
1522+
[self releaseLayer];
1523+
CGContextRef context = [self getLayerContext];
14721524
NSRect rect = [self bounds];
14731525
float r = [defaultBackgroundColor redComponent];
14741526
float g = [defaultBackgroundColor greenComponent];
@@ -1484,7 +1536,7 @@ - (void)clearAll
14841536
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
14851537
fraction:(int)percent color:(int)color
14861538
{
1487-
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
1539+
CGContextRef context = [self getLayerContext];
14881540
NSRect rect = [self rectForRow:row column:col numRows:1 numColumns:1];
14891541

14901542
CGContextSaveGState(context);
@@ -1533,7 +1585,7 @@ - (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
15331585
numColumns:(int)ncols
15341586
{
15351587
// TODO: THIS CODE HAS NOT BEEN TESTED!
1536-
CGContextRef cgctx = [[NSGraphicsContext currentContext] graphicsPort];
1588+
CGContextRef cgctx = [self getLayerContext];
15371589
CGContextSaveGState(cgctx);
15381590
CGContextSetBlendMode(cgctx, kCGBlendModeDifference);
15391591
CGContextSetRGBFillColor(cgctx, 1.0, 1.0, 1.0, 1.0);

0 commit comments

Comments
 (0)