Skip to content

Commit 615fa7a

Browse files
authored
Merge pull request #1128 from ychin/big-sur-toolbar-style-preference-pane-symbols
macOS 11: SF symbols for preference pane / use the right toolbar styles
2 parents 60e6568 + 98da2be commit 615fa7a

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

src/MacVim/MMPreferenceController.m

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,6 @@
1212
#import "MMAppController.h"
1313
#import "Miscellaneous.h"
1414

15-
// On Leopard, we want to use the images provided by the OS for some of the
16-
// toolbar images (NSImageNamePreferencesGeneral and friends). We need to jump
17-
// through some hoops to do that in a way that MacVim still _compiles_ on Tiger
18-
// (life would be easier if we'd require Leopard for building). See
19-
// http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html
20-
// and http://developer.apple.com/technotes/tn2002/tn2064.html
21-
// for how you'd do it with a Leopard build system, and see
22-
// http://lists.cairographics.org/archives/cairo-bugs/2007-December/001818.html
23-
// for why this doesn't work here.
24-
// Using the system images gives us resolution independence and consistency
25-
// with other apps.
26-
27-
#import <dlfcn.h>
28-
29-
30-
NSString* nsImageNamePreferencesGeneral = nil;
31-
NSString* nsImageNamePreferencesAppearance = nil;
32-
NSString* nsImageNamePreferencesAdvanced = nil;
33-
34-
35-
static void loadSymbols()
36-
{
37-
// use dlfcn() instead of the deprecated NSModule api.
38-
void *ptr;
39-
if ((ptr = dlsym(RTLD_DEFAULT, "NSImageNamePreferencesGeneral")) != NULL)
40-
nsImageNamePreferencesGeneral = *(NSString**)ptr;
41-
if ((ptr = dlsym(RTLD_DEFAULT, "NSImageNameColorPanel")) != NULL) // Closest match for default icon for "appearance"
42-
nsImageNamePreferencesAppearance = *(NSString**)ptr;
43-
if ((ptr = dlsym(RTLD_DEFAULT, "NSImageNameAdvanced")) != NULL)
44-
nsImageNamePreferencesAdvanced = *(NSString**)ptr;
45-
}
46-
47-
4815
@implementation MMPreferenceController
4916

5017
- (void)windowDidLoad
@@ -66,6 +33,15 @@ - (void)windowDidLoad
6633
}
6734
#endif
6835
[super windowDidLoad];
36+
37+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
38+
if (@available(macos 11.0, *)) {
39+
// macOS 11 will default to a unified toolbar style unless you use the new
40+
// toolbarStyle to tell it to use a "preference" style, which makes it look nice
41+
// and centered.
42+
[self window].toolbarStyle = NSWindowToolbarStylePreference;
43+
}
44+
#endif
6945
}
7046

7147
- (IBAction)showWindow:(id)sender
@@ -76,30 +52,35 @@ - (IBAction)showWindow:(id)sender
7652

7753
- (void)setupToolbar
7854
{
79-
loadSymbols();
80-
81-
if (nsImageNamePreferencesGeneral != NULL) {
55+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
56+
if (@available(macos 11.0, *)) {
57+
// Use SF Symbols for versions of the OS that supports it to be more unified with OS appearance.
8258
[self addView:generalPreferences
8359
label:@"General"
84-
image:[NSImage imageNamed:nsImageNamePreferencesGeneral]];
85-
} else {
86-
[self addView:generalPreferences label:@"General"];
87-
}
60+
image:[NSImage imageWithSystemSymbolName:@"gearshape" accessibilityDescription:nil]];
8861

89-
if (nsImageNamePreferencesAppearance != NULL) {
9062
[self addView:appearancePreferences
9163
label:@"Appearance"
92-
image:[NSImage imageNamed:nsImageNamePreferencesAppearance]];
93-
} else {
94-
[self addView:appearancePreferences label:@"Appearance"];
64+
image:[NSImage imageWithSystemSymbolName:@"paintbrush" accessibilityDescription:nil]];
65+
66+
[self addView:advancedPreferences
67+
label:@"Advanced"
68+
image:[NSImage imageWithSystemSymbolName:@"gearshape.2" accessibilityDescription:nil]];
9569
}
70+
else
71+
#endif
72+
{
73+
[self addView:generalPreferences
74+
label:@"General"
75+
image:[NSImage imageNamed:NSImageNamePreferencesGeneral]];
76+
77+
[self addView:appearancePreferences
78+
label:@"Appearance"
79+
image:[NSImage imageNamed:NSImageNameColorPanel]];
9680

97-
if (nsImageNamePreferencesAdvanced != NULL) {
9881
[self addView:advancedPreferences
9982
label:@"Advanced"
100-
image:[NSImage imageNamed:nsImageNamePreferencesAdvanced]];
101-
} else {
102-
[self addView:advancedPreferences label:@"Advanced"];
83+
image:[NSImage imageNamed:NSImageNameAdvanced]];
10384
}
10485
}
10586

src/MacVim/MMWindowController.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ - (id)initWithVimController:(MMVimController *)controller
222222
}
223223
#endif
224224

225+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
226+
if (@available(macos 11.0, *)) {
227+
// macOS 11 will default to a unified toolbar style unless you use the new
228+
// toolbarStyle to tell it to use a "preference" style, which makes it look nice
229+
// and centered.
230+
win.toolbarStyle = NSWindowToolbarStyleUnifiedCompact;
231+
}
232+
#endif
233+
225234
[[NSNotificationCenter defaultCenter]
226235
addObserver:self
227236
selector:@selector(applicationDidChangeScreenParameters:)

0 commit comments

Comments
 (0)