Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

. #42

Closed
wants to merge 1 commit into from
Closed

. #42

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/nsterm.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ enum ns_return_frame_mode
struct frame *emacsframe;
int scrollbarsNeedingUpdate;
NSRect ns_userRect;
CALayer *cursor_layer;
}

/* AppKit-side interface */
Expand Down
66 changes: 30 additions & 36 deletions src/nsterm.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Updated by Christian Limpach ([email protected])
#include "macfont.h"
#include <Carbon/Carbon.h>
#include <IOSurface/IOSurface.h>
#include <QuartzCore/QuartzCore.h>
#endif

static EmacsMenu *dockMenu;
Expand Down Expand Up @@ -3064,6 +3065,9 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
return;
}

if (!active_p)
return;

get_phys_cursor_geometry (w, glyph_row, phys_cursor_glyph, &fx, &fy, &h);

/* The above get_phys_cursor_geometry call set w->phys_cursor_width
Expand Down Expand Up @@ -3101,44 +3105,23 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
/* Prevent the cursor from being drawn outside the text area. */
r = NSIntersectionRect (r, ns_row_rect (w, glyph_row, TEXT_AREA));

ns_focus (f, NULL, 0);

NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
[ctx saveGraphicsState];
#ifdef NS_IMPL_GNUSTEP
GSRectClipList (ctx, &r, 1);
#else
NSRectClip (r);
#endif

[FRAME_CURSOR_COLOR (f) set];

switch (cursor_type)
/* the CA cursor doesn't need a drawing context: we directly set its color. */
EmacsView *view = FRAME_NS_VIEW (f);
CALayer *cursor_layer = view->cursor_layer;
if (! cursor_layer)
return;
r.origin.y = [view bounds].size.height - r.size.height - r.origin.y;
[CATransaction begin];
[CATransaction setAnimationDuration:0.1];
cursor_layer.backgroundColor = FRAME_CURSOR_COLOR (f).CGColor;
if (cursor_type == BAR_CURSOR)
{
case DEFAULT_CURSOR:
case NO_CURSOR:
break;
case FILLED_BOX_CURSOR:
/* The call to draw_phys_cursor_glyph can end up undoing the
ns_focus, so unfocus here and regain focus later. */
[ctx restoreGraphicsState];
ns_unfocus (f);
draw_phys_cursor_glyph (w, glyph_row, DRAW_CURSOR);
ns_focus (f, &r, 1);
break;
case HOLLOW_BOX_CURSOR:
/* This works like it does in PostScript, not X Windows. */
[NSBezierPath strokeRect: NSInsetRect (r, 0.5, 0.5)];
[ctx restoreGraphicsState];
break;
case HBAR_CURSOR:
case BAR_CURSOR:
NSRectFill (r);
[ctx restoreGraphicsState];
break;
cursor_glyph = get_phys_cursor_glyph (w);
if ((cursor_glyph->resolved_level & 1) != 0)
r.origin.x += cursor_glyph->pixel_width - r.size.width;
}

ns_unfocus (f);
cursor_layer.frame = r;
[CATransaction commit];
}


Expand Down Expand Up @@ -9234,6 +9217,17 @@ - (instancetype) initWithEmacsFrame: (struct frame *) f
[[self contentView] addSubview:view];
[self makeFirstResponder:view];

/* Overlay a canvas view on top of EmacsView. */
NSView *canvasView = [[NSView alloc] initWithFrame:view.bounds];
canvasView.wantsLayer = YES;
canvasView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[view addSubview:canvasView positioned:NSWindowAbove relativeTo:nil];

/* Create a cursor layer on the canvas. */
view->cursor_layer = [CALayer layer];
[canvasView.layer addSublayer: view->cursor_layer];
view->cursor_layer.frame = CGRectMake(0, 0, 0, 0);

#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
#if MAC_OS_X_VERSION_MAX_ALLOWED > 1090
if ([self respondsToSelector: @selector(useOptimizedDrawing:)])
Expand Down