Skip to content

Commit f2ef091

Browse files
committed
Use a custom I-beam mouse cursor for pre-Mojave OS versions
Prevoiusly, #859 removed the custom high-contrast I-beam mouse cursor in favor of using the system-default I-beam cursor. However, it mostly worked well on 10.14 Mojave or above, as the cursor is designed with dark mode in mind and works well on both bright and dark backgrounds. Since this doesn't work well on older macOS versions, add back the custom cursor and only enable it on those older macOS versions. Fix #910.
1 parent 491433d commit f2ef091

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/MacVim/MMTextViewHelper.m

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,38 @@ - (void)dragTimerFired:(NSTimer *)timer
10281028

10291029
- (void)setCursor
10301030
{
1031+
static NSCursor *ibeamCursor = nil;
1032+
1033+
if (!ibeamCursor) {
1034+
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_14)
1035+
{
1036+
// macOS 10.14 (Mojave) introduced dark mode, and seems to have
1037+
// added a thick white border around the system I-beam cursor,
1038+
// which makes it legible across bright and dark background. Just
1039+
// use it.
1040+
ibeamCursor = [NSCursor IBeamCursor];
1041+
}
1042+
else
1043+
{
1044+
// Pre-Mojave versions the I-beam cursors doesn't have the strong
1045+
// white background and is hard to read on dark background. Use a
1046+
// custom I-beam cursor that has better contrast against dark
1047+
// backgrounds.
1048+
NSImage *ibeamImage = [NSImage imageNamed:@"ibeam"];
1049+
if (ibeamImage) {
1050+
NSSize size = [ibeamImage size];
1051+
NSPoint hotSpot = { size.width*.5f, size.height*.5f };
1052+
1053+
ibeamCursor = [[NSCursor alloc]
1054+
initWithImage:ibeamImage hotSpot:hotSpot];
1055+
}
1056+
if (!ibeamCursor) {
1057+
ASLogWarn(@"Failed to load custom Ibeam cursor");
1058+
ibeamCursor = [NSCursor IBeamCursor];
1059+
}
1060+
}
1061+
}
1062+
10311063
// This switch should match mshape_names[] in misc2.c.
10321064
//
10331065
// We don't fill every shape here. Only the ones that make sense and have
@@ -1037,7 +1069,7 @@ - (void)setCursor
10371069
[[NSCursor arrowCursor] set]; break;
10381070
//case 1: // blank
10391071
case 2: // beam
1040-
[[NSCursor IBeamCursor] set]; break;
1072+
[ibeamCursor set]; break;
10411073
case 3: // updown
10421074
case 4: // udsizing
10431075
[[NSCursor resizeUpDownCursor] set]; break;

src/MacVim/MacVim.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#ifndef NSAppKitVersionNumber10_13
4949
# define NSAppKitVersionNumber10_13 1561
5050
#endif
51+
#ifndef NSAppKitVersionNumber10_14
52+
# define NSAppKitVersionNumber10_14 1671
53+
#endif
5154

5255
#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
5356
// Deprecated constants in 10.12 SDK

src/MacVim/MacVim.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
1DCD00D30E50B2B700460166 /* Undo.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DCD00BE0E50B2B700460166 /* Undo.png */; };
5454
1DD04DEC0C529C5E006CDC2B /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 1DD04DEB0C529C5E006CDC2B /* Credits.rtf */; };
5555
1DD0C20C0C60FFB4008CD84A /* gvimrc in Copy Vim Runtime Files */ = {isa = PBXBuildFile; fileRef = 1DD0C20A0C60FF9A008CD84A /* gvimrc */; };
56+
1DD3D51E0D82D4C9006E4320 /* ibeam.png in Resources */ = {isa = PBXBuildFile; fileRef = 1DD3D51D0D82D4C9006E4320 /* ibeam.png */; };
5657
1DD66ECE0C803D3600EBDAB3 /* MMApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 1DD66ECC0C803D3600EBDAB3 /* MMApplication.m */; };
5758
1DD9F5E50C85D60500E8D5A5 /* SystemColors.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1DD9F5E40C85D60500E8D5A5 /* SystemColors.plist */; };
5859
1DE3F8E70D50F80500052B9E /* Preferences.nib in Resources */ = {isa = PBXBuildFile; fileRef = 1DE3F8E50D50F80500052B9E /* Preferences.nib */; };
@@ -228,6 +229,7 @@
228229
1DCD00BE0E50B2B700460166 /* Undo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Undo.png; path = Toolbar/Undo.png; sourceTree = "<group>"; };
229230
1DD04DEB0C529C5E006CDC2B /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
230231
1DD0C20A0C60FF9A008CD84A /* gvimrc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = gvimrc; sourceTree = "<group>"; };
232+
1DD3D51D0D82D4C9006E4320 /* ibeam.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ibeam.png; sourceTree = "<group>"; };
231233
1DD66ECB0C803D3600EBDAB3 /* MMApplication.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMApplication.h; sourceTree = "<group>"; };
232234
1DD66ECC0C803D3600EBDAB3 /* MMApplication.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MMApplication.m; sourceTree = "<group>"; };
233235
1DD9F5E40C85D60500E8D5A5 /* SystemColors.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SystemColors.plist; sourceTree = "<group>"; };
@@ -554,6 +556,7 @@
554556
1D8BEA73104992290069B072 /* FindAndReplace.nib */,
555557
0395A8A90D72D88B00881434 /* General.png */,
556558
1D22374A0E45DF4800E6FFFF /* Advanced.png */,
559+
1DD3D51D0D82D4C9006E4320 /* ibeam.png */,
557560
1D0F11480D58C77800D5DA09 /* Font */,
558561
1DE9726C0C48050600F96A9F /* Toolbar */,
559562
1DD9F5E40C85D60500E8D5A5 /* SystemColors.plist */,
@@ -842,6 +845,7 @@
842845
1DD9F5E50C85D60500E8D5A5 /* SystemColors.plist in Resources */,
843846
1DE3F8E70D50F80500052B9E /* Preferences.nib in Resources */,
844847
0395A8AA0D72D88B00881434 /* General.png in Resources */,
848+
1DD3D51E0D82D4C9006E4320 /* ibeam.png in Resources */,
845849
1D22374B0E45DF4800E6FFFF /* Advanced.png in Resources */,
846850
1DCD00BF0E50B2B700460166 /* Attention.png in Resources */,
847851
1DCD00C00E50B2B700460166 /* Copy.png in Resources */,

src/MacVim/ibeam.png

193 Bytes
Loading

0 commit comments

Comments
 (0)