Skip to content

Commit e1bc03b

Browse files
committed
Touch Bar add documentation, support enabled states, and system icons
Enabled states now work. E.g. a mapped Touch Bar button using "vmenu TouchBar.DoStuff <nop>" will not show up in normal mode. Also support specifying default Apple template icons. E.g. "an icon=NSTouchBarListViewTemplate TouchBar.ShowList <Nop>" Remove default TouchBar buttons as there were too many of them and most of them are unlikely to be heavily used as there are direct Vim command equivalent. Instead just add a single fullscreen toggle button. This can be changed later.
1 parent 0d62189 commit e1bc03b

6 files changed

Lines changed: 116 additions & 48 deletions

File tree

runtime/doc/gui_mac.txt

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ The MacVim Graphical User Interface *macvim* *gui-macvim*
1212
4. Special colors |macvim-colors|
1313
5. Menus |macvim-menus|
1414
6. Toolbar |macvim-toolbar|
15-
7. Dialogs |macvim-dialogs|
16-
8. System services |macvim-services|
17-
9. mvim:// URL handler |macvim-url-handler|
18-
10. Keyboard shortcuts |macvim-shortcuts|
19-
11. Trackpad gestures |macvim-gestures|
20-
12. International |macvim-international|
21-
13. Known bugs/missing features |macvim-todo|
22-
14. Hints |macvim-hints|
15+
7. Touch Bar |macvim-touchbar|
16+
8. Dialogs |macvim-dialogs|
17+
9. System services |macvim-services|
18+
10. mvim:// URL handler |macvim-url-handler|
19+
11. Keyboard shortcuts |macvim-shortcuts|
20+
12. Trackpad gestures |macvim-gestures|
21+
13. International |macvim-international|
22+
14. Known bugs/missing features |macvim-todo|
23+
15. Hints |macvim-hints|
2324

2425
Other relevant documentation:
2526
|gui.txt| For generic items of the GUI.
@@ -467,19 +468,47 @@ empty space which will shink or expand so that the items to the right of it
467468
are right-aligned. A space (flexspace) will be created for any toolbar item
468469
whose name begins with "-space" ("-flexspace") and ends with "-"
469470

470-
Toolbar icons should be tiff, png or icns, of dimension 32x32 or 24x24 pixels.
471-
The larger size is used when 'tbis' is "medium" or "large", otherwise the
472-
smaller size is used (which is the default). If the icon file only contains
473-
one dimension then Mac OS X will scale the icon to the appropriate dimension
474-
if necessary. To avoid this, use a file format which supports multiple
475-
resolutions (such as icns) and provide both 32x32 and 24x24 versions of the
476-
icon.
471+
Toolbar icons should be tiff, png, icns, or heic, of dimension 32x32 or 24x24
472+
pixels. The larger size is used when 'tbis' is "medium" or "large", otherwise
473+
the smaller size is used (which is the default). If the icon file only
474+
contains one dimension then Mac OS X will scale the icon to the appropriate
475+
dimension if necessary. To avoid this, use a file format which supports
476+
multiple resolutions (such as icns) and provide both 32x32 and 24x24 versions
477+
of the icon.
477478

478479
Note: Only a subset of the builtin toolbar items presently have icons. If no
479480
icon can be found a warning triangle is displayed instead.
480481

481482
==============================================================================
482-
7. Dialogs *macvim-dialogs*
483+
7. Touch Bar *macvim-touchbar*
484+
485+
Touch Bar in MacVim works similar to the toolbar (see |macvim-toolbar|). The
486+
difference is that you use the special menu "TouchBar" instead of "ToolBar": >
487+
:an TouchBar.Hello :echo "Hello"<CR>
488+
489+
The separators work similar to how toolbars work: >
490+
:an TouchBar.-Sep- <Nop>
491+
:an TouchBar.-space1- <Nop>
492+
:an TouchBar.-flexspace2- <Nop>
493+
494+
The first example is a Vim separator (see |menu-separator|) and injects a
495+
space between two buttons. The second creates a smaller space than a normal
496+
separator and are specified by names that begin with "-space" and ends with
497+
"-". The third creates a flexible empty space which will shrink or expand so
498+
that items after it will be right-aligned, and is specified by names that
499+
begin with "-flexspace" and ends with "-".
500+
501+
You can specify icons for Touch Bar buttons the same way for toolbar icons.
502+
Touch Bar icons should ideally be 36x36 pixels, and no larger than 44x44
503+
pixels. You can also use default template icons provided by Apple by using
504+
their template names. An example: >
505+
:an icon=NSTouchBarListViewTemplate TouchBar.ShowList <Nop>
506+
507+
This feature only works on Mac devices that come with Touch Bars. On the ones
508+
that don't, nothing will show up.
509+
510+
==============================================================================
511+
8. Dialogs *macvim-dialogs*
483512

484513
Dialogs can be controlled with the keyboard in two ways. By default each
485514
button in a dialog is bound to a key. The button that is highlighted by blue
@@ -498,7 +527,7 @@ select the current button. The current button is indicated with a blue
498527
outline.
499528

500529
==============================================================================
501-
8. System services *macvim-services*
530+
9. System services *macvim-services*
502531

503532
MacVim supports two system services. These can be accessed from the MacVim
504533
submenu in the Services menu or by right-clicking a selection. For services
@@ -516,7 +545,7 @@ The services respect the "Open files from applications" setting in the general
516545
preferences.
517546

518547
==============================================================================
519-
9. mvim:// URL handler *mvim://* *macvim-url-handler*
548+
10. mvim:// URL handler *mvim://* *macvim-url-handler*
520549

521550
MacVim supports a custom URL handler for "mvim://" URLs. The handler is
522551
supposed to be compatible to TextMate's URL scheme as documented at >
@@ -537,7 +566,7 @@ will open the file /etc/profile on line 20 when clicked in a web browser.
537566
Note that url has to be a file:// url pointing to an existing local file.
538567

539568
==============================================================================
540-
10. Keyboard shortcuts *macvim-shortcuts*
569+
11. Keyboard shortcuts *macvim-shortcuts*
541570

542571
Most keyboard shortcuts in MacVim are bound to menu items and can be
543572
discovered by looking through the menus (see |macvim-menus| on how to create
@@ -617,7 +646,7 @@ sometimes be slightly involved. Here are all the things you need to consider:
617646
- A few command key mappings are set up by MacVim, see |cmd-movement|.
618647

619648
==============================================================================
620-
11. Trackpad gestures *macvim-gestures*
649+
12. Trackpad gestures *macvim-gestures*
621650

622651
MacVim supports trackpad swipe gestures. By default this can be used to
623652
navigate back/forward in the help (try it!).
@@ -648,7 +677,7 @@ As another example, here is how to switch buffers by swiping left/right: >
648677
See the section on |key-mapping| for more help on how to map keys.
649678

650679
==============================================================================
651-
12. International *macvim-international*
680+
13. International *macvim-international*
652681

653682
When editing non-English text it may be convenient to keep separate keyboard
654683
layouts for normal and insert mode. This is supported via the 'imd' option on
@@ -669,7 +698,7 @@ wrong layout when going back to normal mode, then select the layout you want
669698
to use in normal mode and type ":set imd" followed by ":set noimd".
670699

671700
==============================================================================
672-
13. Known bugs/missing features *macvim-todo*
701+
14. Known bugs/missing features *macvim-todo*
673702

674703
This list is by no means exhaustive, it only enumerates some of the more
675704
prominent bugs/missing features.
@@ -693,7 +722,7 @@ This is also the best place for making feature requests as well as for asking
693722
general questions about MacVim.
694723

695724
==============================================================================
696-
14. Hints *macvim-hints*
725+
15. Hints *macvim-hints*
697726

698727
In this section some general (not necessarily MacVim specific) hints are
699728
given.

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7428,6 +7428,7 @@ macvim-start gui_mac.txt /*macvim-start*
74287428
macvim-tablabel gui_mac.txt /*macvim-tablabel*
74297429
macvim-todo gui_mac.txt /*macvim-todo*
74307430
macvim-toolbar gui_mac.txt /*macvim-toolbar*
7431+
macvim-touchbar gui_mac.txt /*macvim-touchbar*
74317432
macvim-url-handler gui_mac.txt /*macvim-url-handler*
74327433
macvim-user-defaults gui_mac.txt /*macvim-user-defaults*
74337434
macvim-window-title gui_mac.txt /*macvim-window-title*

runtime/menu.vim

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,20 +1288,26 @@ if has("gui_macvim")
12881288
endif
12891289

12901290
if has("touchbar")
1291-
an TouchBar.Open :browse confirm e<CR>
1292-
an <silent> TouchBar.Save :if expand("%") == ""<Bar>browse confirm w<Bar>else<Bar>confirm w<Bar>endif<CR>
1293-
an TouchBar.SaveAll :browse confirm wa<CR>
1294-
1295-
an TouchBar.-sep1- <Nop>
1296-
an TouchBar.Undo u
1297-
an TouchBar.Redo <C-R>
1298-
1299-
an TouchBar.-sep2- <Nop>
1300-
vnoremenu TouchBar.Cut "+x
1301-
vnoremenu TouchBar.Copy "+y
1302-
cnoremenu TouchBar.Copy <C-Y>
1303-
nnoremenu TouchBar.Paste "+gP
1304-
cnoremenu TouchBar.Paste <C-R>+
1291+
" Set up default Touch Bar buttons.
1292+
" 1. Smart fullscreen icon that toggles between going full screen or not.
1293+
an icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen<CR>
1294+
1295+
let s:touchbar_fullscreen=0
1296+
func! s:SetupFullScreenTouchBar()
1297+
if &fullscreen && s:touchbar_fullscreen == 0
1298+
aun TouchBar.EnterFullScreen
1299+
an icon=NSTouchBarExitFullScreenTemplate 1.10 TouchBar.ExitFullScreen :set nofullscreen<CR>
1300+
let s:touchbar_fullscreen = 1
1301+
elseif !&fullscreen && s:touchbar_fullscreen == 1
1302+
aun TouchBar.ExitFullScreen
1303+
an icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen<CR>
1304+
let s:touchbar_fullscreen = 0
1305+
endif
1306+
endfunc
1307+
aug FullScreenTouchBar
1308+
au!
1309+
au VimResized * call <SID>SetupFullScreenTouchBar()
1310+
aug END
13051311
endif
13061312

13071313
" vim: set sw=2 :

src/MacVim/MMVimController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
NSTouchBar *touchbar;
3333
NSMutableDictionary *touchbarItemDict;
3434
NSMutableArray *touchbarItemOrder;
35+
NSMutableSet *touchbarDisabledItems;
3536
#endif
3637

3738
int pid;

src/MacVim/MMVimController.m

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier
136136
toolbarItemDict = [[NSMutableDictionary alloc] init];
137137
touchbarItemDict = [[NSMutableDictionary alloc] init];
138138
touchbarItemOrder = [[NSMutableArray alloc] init];
139+
touchbarDisabledItems = [[NSMutableSet alloc] init];
139140
#endif
140141
pid = processIdentifier;
141142
creationDate = [[NSDate alloc] init];
@@ -188,6 +189,7 @@ - (void)dealloc
188189
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
189190
[touchbarItemDict release]; touchbarItemDict = nil;
190191
[touchbarItemOrder release]; touchbarItemOrder = nil;
192+
[touchbarDisabledItems release]; touchbarDisabledItems = nil;
191193
[touchbar release]; touchbar = nil;
192194
#endif
193195
[popupMenuItems release]; popupMenuItems = nil;
@@ -505,7 +507,28 @@ - (NSTouchBar *)makeTouchBar
505507
{
506508
touchbar = [[NSTouchBar alloc] init];
507509
touchbar.delegate = self;
508-
touchbar.defaultItemIdentifiers = [NSArray arrayWithArray: touchbarItemOrder];
510+
511+
NSMutableArray *filteredTouchbarItemOrder = [NSMutableArray array];
512+
for (NSString *label in touchbarItemOrder) {
513+
if (![touchbarDisabledItems containsObject:label]) {
514+
if ([touchbarItemDict objectForKey:label] == nil) {
515+
// The label begins and ends with '-'; decided which kind of separator
516+
// item it is by looking at the prefix.
517+
if ([label hasPrefix:@"-space"]) {
518+
label = NSTouchBarItemIdentifierFixedSpaceSmall;
519+
} else if ([label hasPrefix:@"-flexspace"]) {
520+
label = NSTouchBarItemIdentifierFlexibleSpace;
521+
} else {
522+
label = NSTouchBarItemIdentifierFixedSpaceLarge;
523+
}
524+
}
525+
526+
[filteredTouchbarItemOrder addObject:label];
527+
}
528+
}
529+
[filteredTouchbarItemOrder addObject:NSTouchBarItemIdentifierOtherItemsProxy];
530+
531+
touchbar.defaultItemIdentifiers = filteredTouchbarItemOrder;
509532
return touchbar;
510533
}
511534

@@ -1173,7 +1196,7 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc
11731196
}
11741197
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
11751198
if ([rootName isEqual:MMTouchbarMenuName]) {
1176-
if (toolbar && [desc count] == 2)
1199+
if ([desc count] == 2)
11771200
[self addTouchbarItemWithLabel:title icon:icon atIndex:idx];
11781201
return;
11791202
}
@@ -1245,6 +1268,7 @@ - (void)removeMenuItemWithDescriptor:(NSArray *)desc
12451268
if ([desc count] == 2) {
12461269
[touchbarItemOrder removeObject:title];
12471270
[touchbarItemDict removeObjectForKey:title];
1271+
[touchbarDisabledItems removeObject:title];
12481272
[windowController setTouchBar:nil];
12491273
}
12501274
return;
@@ -1286,6 +1310,14 @@ - (void)enableMenuItemWithDescriptor:(NSArray *)desc state:(BOOL)on
12861310
}
12871311
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
12881312
if ([rootName isEqual:MMTouchbarMenuName]) {
1313+
if ([desc count] == 2) {
1314+
NSString *title = [desc lastObject];
1315+
if (on)
1316+
[touchbarDisabledItems removeObject:title];
1317+
else
1318+
[touchbarDisabledItems addObject:title];
1319+
[windowController setTouchBar:nil];
1320+
}
12891321
return;
12901322
}
12911323
#endif
@@ -1376,15 +1408,7 @@ - (void)addTouchbarItemWithLabel:(NSString *)label
13761408
label = NSTouchBarItemIdentifierFixedSpaceLarge;
13771409
} else if ([label length] >= 2 && [label hasPrefix:@"-"]
13781410
&& [label hasSuffix:@"-"]) {
1379-
// The label begins and ends with '-'; decided which kind of separator
1380-
// item it is by looking at the prefix.
1381-
if ([label hasPrefix:@"-space"]) {
1382-
label = NSTouchBarItemIdentifierFixedSpaceSmall;
1383-
} else if ([label hasPrefix:@"-flexspace"]) {
1384-
label = NSTouchBarItemIdentifierFlexibleSpace;
1385-
} else {
1386-
label = NSTouchBarItemIdentifierFixedSpaceLarge;
1387-
}
1411+
// These will be converted to fixed/flexible space identifiers later, when "makeTouchBar" is called.
13881412
} else {
13891413
NSButton* button = [NSButton buttonWithTitle:label target:windowController action:@selector(vimTouchbarItemAction:)];
13901414
NSCustomTouchBarItem *item =

src/MacVim/gui_macvim.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,13 @@
799799
// then a warning icon will be displayed).
800800
if (!icon)
801801
icon = lookup_toolbar_item(menu->iconidx);
802+
803+
// Last step is to see if this is a standard Apple template icon. The
804+
// touch bar templates are of the form "NSTouchBar*Template".
805+
if (!icon)
806+
if (menu->iconfile && STRNCMP(menu->iconfile, "NSTouchBar", 10) == 0) {
807+
icon = menu->iconfile;
808+
}
802809
}
803810

804811
[[MMBackend sharedInstance] queueMessage:AddMenuItemMsgID properties:

0 commit comments

Comments
 (0)