Skip to content

MBP Touchbar Support (take 2) #715

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

Merged
merged 4 commits into from
Jul 30, 2018
Merged
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 runtime/doc/eval.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9415,6 +9415,7 @@ tgetent Compiled with tgetent support, able to use a termcap
timers Compiled with |timer_start()| support.
title Compiled with window title support |'title'|.
toolbar Compiled with support for |gui-toolbar|.
touchbar Compiled with support for Touch Bar in MacVim.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not 100% if we should expose a feature test for this, but I guess if toolbar is already one, why not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you that you've exposed it as Tool bar and Touch Bar are different. One can be enabled without other

transparency Compiled with 'transparency' support.
ttyin input is a terminal (tty)
ttyout output is a terminal (tty)
Expand Down
77 changes: 53 additions & 24 deletions runtime/doc/gui_mac.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ The MacVim Graphical User Interface *macvim* *gui-macvim*
4. Special colors |macvim-colors|
5. Menus |macvim-menus|
6. Toolbar |macvim-toolbar|
7. Dialogs |macvim-dialogs|
8. System services |macvim-services|
9. mvim:// URL handler |macvim-url-handler|
10. Keyboard shortcuts |macvim-shortcuts|
11. Trackpad gestures |macvim-gestures|
12. International |macvim-international|
13. Known bugs/missing features |macvim-todo|
14. Hints |macvim-hints|
7. Touch Bar |macvim-touchbar|
8. Dialogs |macvim-dialogs|
9. System services |macvim-services|
10. mvim:// URL handler |macvim-url-handler|
11. Keyboard shortcuts |macvim-shortcuts|
12. Trackpad gestures |macvim-gestures|
13. International |macvim-international|
14. Known bugs/missing features |macvim-todo|
15. Hints |macvim-hints|

Other relevant documentation:
|gui.txt| For generic items of the GUI.
Expand Down Expand Up @@ -345,7 +346,7 @@ associated: a title, a key equivalent and an action message. When a menu is
displayed the title is shown on the left and the key equivalent (if any) is
shown on the right. Key equivalents enable you to access a menu item using
the keyboard instead of having to use the mouse. When a menu item is clicked
it will send it's associated action message. Actions can be used to instruct
it will send its associated action message. Actions can be used to instruct
MacVim to paste some text (paste:), open a new window (newWindow:), etc.
Certain actions are standard throughout OS X which is why MacVim must be able
to set these for each menu item. (E.g. the menu item "Edit.Paste" must be
Expand Down Expand Up @@ -467,19 +468,47 @@ empty space which will shink or expand so that the items to the right of it
are right-aligned. A space (flexspace) will be created for any toolbar item
whose name begins with "-space" ("-flexspace") and ends with "-"

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

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

==============================================================================
7. Dialogs *macvim-dialogs*
7. Touch Bar *macvim-touchbar*

Touch Bar in MacVim works similar to the toolbar (see |macvim-toolbar|). The
difference is that you use the special menu "TouchBar" instead of "ToolBar": >
:an TouchBar.Hello :echo "Hello"<CR>

The separators work similar to how toolbars work: >
:an TouchBar.-Sep- <Nop>
:an TouchBar.-space1- <Nop>
:an TouchBar.-flexspace2- <Nop>

The first example is a Vim separator (see |menu-separator|) and injects a
space between two buttons. The second creates a smaller space than a normal
separator and are specified by names that begin with "-space" and ends with
"-". The third creates a flexible empty space which will shrink or expand so
that items after it will be right-aligned, and is specified by names that
begin with "-flexspace" and ends with "-".

You can specify icons for Touch Bar buttons the same way for toolbar icons.
Touch Bar icons should ideally be 36x36 pixels, and no larger than 44x44
pixels. You can also use default template icons provided by Apple by using
their template names. An example: >
:an icon=NSTouchBarListViewTemplate TouchBar.ShowList <Nop>

This feature only works on Mac devices that come with Touch Bars. On the ones
that don't, nothing will show up.

==============================================================================
8. Dialogs *macvim-dialogs*

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

==============================================================================
8. System services *macvim-services*
9. System services *macvim-services*

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

==============================================================================
9. mvim:// URL handler *mvim://* *macvim-url-handler*
10. mvim:// URL handler *mvim://* *macvim-url-handler*

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

==============================================================================
10. Keyboard shortcuts *macvim-shortcuts*
11. Keyboard shortcuts *macvim-shortcuts*

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

==============================================================================
11. Trackpad gestures *macvim-gestures*
12. Trackpad gestures *macvim-gestures*

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

==============================================================================
12. International *macvim-international*
13. International *macvim-international*

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

==============================================================================
13. Known bugs/missing features *macvim-todo*
14. Known bugs/missing features *macvim-todo*

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

==============================================================================
14. Hints *macvim-hints*
15. Hints *macvim-hints*

In this section some general (not necessarily MacVim specific) hints are
given.
Expand Down
1 change: 1 addition & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -7428,6 +7428,7 @@ macvim-start gui_mac.txt /*macvim-start*
macvim-tablabel gui_mac.txt /*macvim-tablabel*
macvim-todo gui_mac.txt /*macvim-todo*
macvim-toolbar gui_mac.txt /*macvim-toolbar*
macvim-touchbar gui_mac.txt /*macvim-touchbar*
macvim-url-handler gui_mac.txt /*macvim-url-handler*
macvim-user-defaults gui_mac.txt /*macvim-user-defaults*
macvim-window-title gui_mac.txt /*macvim-window-title*
Expand Down
23 changes: 23 additions & 0 deletions runtime/menu.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1287,4 +1287,27 @@ if has("gui_macvim")
macm Help.MacVim\ Website action=openWebsite:
endif

if has("touchbar")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous review there was a comment about potentially having too many default Touch Bar buttons. I addressed this in the pull request descriptions, but I basically removed all the original ones and just added a full screen button that can toggle icon depending on what state it's in. I think most users will prefer a close to empty Touch Bar for customization so it's not worth having too many defaults (I just think having a couple that works well is a good thing to entice users to learn how to customize it).

" Set up default Touch Bar buttons.
" 1. Smart fullscreen icon that toggles between going full screen or not.
an icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen<CR>

let s:touchbar_fullscreen=0
func! s:SetupFullScreenTouchBar()
if &fullscreen && s:touchbar_fullscreen == 0
aun TouchBar.EnterFullScreen
an icon=NSTouchBarExitFullScreenTemplate 1.10 TouchBar.ExitFullScreen :set nofullscreen<CR>
let s:touchbar_fullscreen = 1
elseif !&fullscreen && s:touchbar_fullscreen == 1
aun TouchBar.ExitFullScreen
an icon=NSTouchBarEnterFullScreenTemplate 1.10 TouchBar.EnterFullScreen :set fullscreen<CR>
let s:touchbar_fullscreen = 0
endif
endfunc
aug FullScreenTouchBar
au!
au VimResized * call <SID>SetupFullScreenTouchBar()
aug END
endif

" vim: set sw=2 :
18 changes: 16 additions & 2 deletions src/MacVim/MMVimController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@



@interface MMVimController : NSObject<NSToolbarDelegate,
NSOpenSavePanelDelegate>
@interface MMVimController : NSObject<
NSToolbarDelegate
, NSOpenSavePanelDelegate
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
, NSTouchBarDelegate
#endif
>
{
unsigned identifier;
BOOL isInitialized;
Expand All @@ -28,6 +33,12 @@
// TODO: Move all toolbar code to window controller?
NSToolbar *toolbar;
NSMutableDictionary *toolbarItemDict;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
NSTouchBar *touchbar;
NSMutableDictionary *touchbarItemDict;
NSMutableArray *touchbarItemOrder;
NSMutableSet *touchbarDisabledItems;
#endif

int pid;
NSString *serverName;
Expand Down Expand Up @@ -65,4 +76,7 @@
- (id)evaluateVimExpressionCocoa:(NSString *)expr
errorString:(NSString **)errstr;
- (void)processInputQueue:(NSArray *)queue;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12_2
- (NSTouchBar *)makeTouchBar;
#endif
@end
Loading