Skip to content

MBP Touchbar Support #568

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

Closed
wants to merge 1 commit into from
Closed

Conversation

wiomoc
Copy link
Contributor

@wiomoc wiomoc commented Oct 21, 2017

Proof of Concept
This needs some work

@wiomoc
Copy link
Contributor Author

wiomoc commented Oct 31, 2017

touch bar bild 2017-08-09 um 20 21 22

@jpetrie
Copy link
Contributor

jpetrie commented Nov 4, 2017

Thanks for this!

Apart from some minor style nitpicks (I'll go through and leave comments on the specific lines), this mostly looks reasonable. I don't have the hardware to test it. When you say "this needs some work," what sort of work are you thinking of?

Copy link
Contributor

@jpetrie jpetrie left a comment

Choose a reason for hiding this comment

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

As I said in the PR comment, most of my notes here are really minor nitpicky stuff about indenting consistency. I'm mostly concerned about the discussion in menu.vim and the else structure in enableMenuItemWithDescriptor... plus having some idea of what other "work" you think remains here.

@@ -1266,4 +1266,21 @@ if has("gui_macvim")
macm Help.MacVim\ Website action=openWebsite:
endif

if has("touchbar")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better place to do this setup? I'm specifically thinking that customizing the Touch Bar items will likely be something people will want to do quite a lot, and that having to first go through and delete these menu items is somewhat tedious. It might be better if the initial setup of the Touch Bar menu could be deferred somewhere so users could set a global variable in their vimrc to suppress default menu generation and instead generate the items themselves.

@@ -28,6 +28,11 @@
// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

The indenting on this preprocessor line (and the corresponding #endif) is off.

@@ -129,7 +129,11 @@ - (id)initWithBackend:(id)backend pid:(int)processIdentifier
[[MMWindowController alloc] initWithVimController:self];
backendProxy = [backend retain];
popupMenuItems = [[NSMutableArray alloc] init];
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
Copy link
Contributor

Choose a reason for hiding this comment

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

The indent on this #if/#endif pair is off.

@@ -178,6 +182,11 @@ - (void)dealloc

[toolbarItemDict release]; toolbarItemDict = nil;
[toolbar release]; toolbar = nil;
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
Copy link
Contributor

Choose a reason for hiding this comment

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

The indent on this #if/#endif pair is off.

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
- (NSTouchBar *)makeTouchBar
{
touchbar = [[NSTouchBar alloc] init];
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 503 - 506 have mixed tab/space indenting and are too far in.

@@ -1081,7 +1108,10 @@ - (void)addMenuWithDescriptor:(NSArray *)desc atIndex:(int)idx

return;
}

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
Copy link
Contributor

Choose a reason for hiding this comment

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

The indent of this #if/#endif block is off.

@@ -1132,7 +1162,13 @@ - (void)addMenuItemWithDescriptor:(NSArray *)desc
[self addToolbarItemWithLabel:title tip:tip icon:icon atIndex:idx];
return;
}

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
if ([rootName isEqual:@"TouchBar"]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point it might be worth writing isTouchBarMenuName or similar, or at least making the name a constant.

@@ -1228,7 +1273,11 @@ - (void)enableMenuItemWithDescriptor:(NSArray *)desc state:(BOOL)on
NSString *title = [desc lastObject];
[[toolbar itemWithItemIdentifier:title] setEnabled:on];
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, this should be written in a way that doesn't inject the preprocessor check between the else and the if; this kind of construct is error-prone and can be difficult to follow (I realize it might be elsewhere in MacVim's codebase, but I'd rather we don't propagate it). I'd rather see something more like:

} else {
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
  if ([rootName isEqual:@"TouchBar")) { return; }
#endif

// Use tag to set...

} else {
label = NSTouchBarItemIdentifierFixedSpaceLarge;
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole else block has mixed tab/space indenting and seemingly overly deep indents.

#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_12
- (NSTouchBar *)makeTouchBar
{
return [vimController makeTouchBar];
Copy link
Contributor

Choose a reason for hiding this comment

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

A tab is used to indent here instead of spaces.

@taiyangc
Copy link

taiyangc commented Jan 9, 2018

Awesome idea! Is it possible to further user-customize the touch bar shortcuts to specific macros?

@getaaron
Copy link

getaaron commented May 4, 2018

@wiomoc @jpetrie any updates on this? would love to see it merged

@ychin
Copy link
Member

ychin commented Jul 27, 2018

I have the same question on updates. I'm quite interested in having TouchBar support as right now it doesn't do anything when I have MacVim up :(. (macOS allows you to force it to only show function keys when MacVim is up but if you do that it's hard to adjust volume, etc)

I don't mind taking this over and help push this through if the original author is no longer interested. I think this at least needs some documentation in gui_mac.txt in addition to the existing comments.

Played around with it a little bit, and some additional potential improvements below. These are really just random ideas. Could be future pull requests after this is in:

  1. You can't pan through the touch bar items if there are too many. Ideally you should be able to do that.
  • An alternative is expose the "Customize TouchBar…" option to give native TouchBar customization. Not sure how much work that is.
  1. Different modes are not respected right now. E.g. vnoremenu TouchBar.VisualOnly <Nop> would still be active in normal mode. Normal menus and toolbars do respect the modes and gray out the items. I think for touch bar we don't even need to gray out the menu items. Just hide them to save space.
  2. Nesting is not allowed right now. I.e. you cannot do :an TouchBar.Grouping.Item1 <Nop>. I'm thinking it could surface "Grouping" and when you tap on it it will show the individual items under it. This is useful as TouchBar's real estate is pretty small. E.g. you can use this to group debugger controls.
  • Another idea is to show all the subitems, but grouped together. This saves the extra tap and allow you to see what the options are.
  1. Color support. Touchbar items can have customized colors rather than the default ones.

  2. Kind of extra credit, but support other GUI widgets. Maybe this gets a little too outside of what Vim usually is like, but examples range from using the standard template images (https://developer.apple.com/design/human-interface-guidelines/macos/touch-bar/touch-bar-icons-and-images/) to supporting scrubber. You can kind of go down a rabbit hole on this one though when trying to shoehorn support for native TouchBar APIs onto Vim APIs.

@jpetrie
Copy link
Contributor

jpetrie commented Jul 27, 2018

@ychin

I don't mind taking this over and help push this through if the original author is no longer interested.

Given the amount of time this PR has sat here I think it would be fine for you to do so. As I noted in my initial review, most of what I'd want to see fixed before merging are just style issues to try and keep the code consistent. If you can build a PR that incorporates this original change and fixes those, it would probably get merged pretty quickly.

I don't have hardware to test it on, and I'm not personally that interested in the feature, but I would like to see more contributors since I don't have much time to devote myself. So by all means, if you want to pick this up and run with it, please do so!

@ychin
Copy link
Member

ychin commented Jul 29, 2018

I just submitted a new PR (#715) which takes this current patch and fixed up misc issues and added features.

@jpetrie
Copy link
Contributor

jpetrie commented Jul 29, 2018

Cool; I will take a look at it today.

@jpetrie jpetrie closed this in #715 Jul 30, 2018
@ychin ychin added Input Issues related to keyboard or other types of input UI Issues related to UI elements, tabs, scrollbars, window resizing, etc. and removed Input Issues related to keyboard or other types of input labels Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI Issues related to UI elements, tabs, scrollbars, window resizing, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants