Skip to content

Commit ab1e570

Browse files
authored
Merge pull request #715 from ychin/touchbar
MBP Touchbar Support (take 2)
2 parents ea812c1 + 515ef9f commit ab1e570

File tree

11 files changed

+275
-39
lines changed

11 files changed

+275
-39
lines changed

runtime/doc/eval.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9424,6 +9424,7 @@ tgetent Compiled with tgetent support, able to use a termcap
94249424
timers Compiled with |timer_start()| support.
94259425
title Compiled with window title support |'title'|.
94269426
toolbar Compiled with support for |gui-toolbar|.
9427+
touchbar Compiled with support for Touch Bar in MacVim.
94279428
transparency Compiled with 'transparency' support.
94289429
ttyin input is a terminal (tty)
94299430
ttyout output is a terminal (tty)

runtime/doc/gui_mac.txt

Lines changed: 53 additions & 24 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.
@@ -345,7 +346,7 @@ associated: a title, a key equivalent and an action message. When a menu is
345346
displayed the title is shown on the left and the key equivalent (if any) is
346347
shown on the right. Key equivalents enable you to access a menu item using
347348
the keyboard instead of having to use the mouse. When a menu item is clicked
348-
it will send it's associated action message. Actions can be used to instruct
349+
it will send its associated action message. Actions can be used to instruct
349350
MacVim to paste some text (paste:), open a new window (newWindow:), etc.
350351
Certain actions are standard throughout OS X which is why MacVim must be able
351352
to set these for each menu item. (E.g. the menu item "Edit.Paste" must be
@@ -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!).
@@ -652,7 +681,7 @@ As another example, here is how to switch buffers by swiping left/right: >
652681
See the section on |key-mapping| for more help on how to map keys.
653682

654683
==============================================================================
655-
12. International *macvim-international*
684+
13. International *macvim-international*
656685

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

675704
==============================================================================
676-
13. Known bugs/missing features *macvim-todo*
705+
14. Known bugs/missing features *macvim-todo*
677706

678707
This list is by no means exhaustive, it only enumerates some of the more
679708
prominent bugs/missing features.
@@ -697,7 +726,7 @@ This is also the best place for making feature requests as well as for asking
697726
general questions about MacVim.
698727

699728
==============================================================================
700-
14. Hints *macvim-hints*
729+
15. Hints *macvim-hints*
701730

702731
In this section some general (not necessarily MacVim specific) hints are
703732
given.

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7430,6 +7430,7 @@ macvim-start gui_mac.txt /*macvim-start*
74307430
macvim-tablabel gui_mac.txt /*macvim-tablabel*
74317431
macvim-todo gui_mac.txt /*macvim-todo*
74327432
macvim-toolbar gui_mac.txt /*macvim-toolbar*
7433+
macvim-touchbar gui_mac.txt /*macvim-touchbar*
74337434
macvim-url-handler gui_mac.txt /*macvim-url-handler*
74347435
macvim-user-defaults gui_mac.txt /*macvim-user-defaults*
74357436
macvim-window-title gui_mac.txt /*macvim-window-title*

runtime/menu.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,4 +1287,27 @@ if has("gui_macvim")
12871287
macm Help.MacVim\ Website action=openWebsite:
12881288
endif
12891289

1290+
if has("touchbar")
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
1311+
endif
1312+
12901313
" vim: set sw=2 :

src/MacVim/MMVimController.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515

1616

1717

18-
@interface MMVimController : NSObject<NSToolbarDelegate,
19-
NSOpenSavePanelDelegate>
18+
@interface MMVimController : NSObject<
19+
NSToolbarDelegate
20+
, NSOpenSavePanelDelegate
21+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
22+
, NSTouchBarDelegate
23+
#endif
24+
>
2025
{
2126
unsigned identifier;
2227
BOOL isInitialized;
@@ -28,6 +33,12 @@
2833
// TODO: Move all toolbar code to window controller?
2934
NSToolbar *toolbar;
3035
NSMutableDictionary *toolbarItemDict;
36+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
37+
NSTouchBar *touchbar;
38+
NSMutableDictionary *touchbarItemDict;
39+
NSMutableArray *touchbarItemOrder;
40+
NSMutableSet *touchbarDisabledItems;
41+
#endif
3142

3243
int pid;
3344
NSString *serverName;
@@ -65,4 +76,7 @@
6576
- (id)evaluateVimExpressionCocoa:(NSString *)expr
6677
errorString:(NSString **)errstr;
6778
- (void)processInputQueue:(NSArray *)queue;
79+
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
80+
- (NSTouchBar *)makeTouchBar;
81+
#endif
6882
@end

0 commit comments

Comments
 (0)