Using macbook touchbar in Java

by Thizzer

I was never a huge fan of the touchbar on the Macbook. Previously I had only scarcely used the touchbar for adjusting volume and display brightness. But recently I have found a great example of what the touchbar can be used for.

TL;WR; I am working on a Java library called JTouchBar that allows access to the touchbar features on the new macbooks from Java through JNI. You can check it out on Github at; https://github.com/Nentix/JTouchBar

 

I use different machines and OSes to do my developing, most determining in which I use is wether or not I feel like sitting behing my desk (resulting in my Windows desktop) or just want to sit on the couch (which results in my macOS macbook).

 

On my macbook I use Visual Studio Code for simple prototyping and scripting. VSCode is getting regular updates and supports a lot of languages by the use of extensions.

 

Recently an update for VSCode was released in which support was added support for the touchbar and when I glanced through the release notes I saw the image below and was immediately excited.

 

 

They added support for debugging to the touchbar. Most IDEs support hotkeys for access debugging features like continue, step-over, step-into and so on and per default these hotkeys are mapped to the F-keys which are no longer really a thing on the new macbooks. Yes, you can access them in the touchbar by holding the FN-key, but in my mind that defeats the purpose.

 

Now I’ve been working with the debugging touchbar in VSCode for some days now and it is somewhat of a godsend for speeding up debugging. Even when I was used to using the F-keys I was always mixing up the keys for step-over and step-into resulting in having to run the application again to actually get to the point I wanted to debug. This addition to VSCode made debugging a lot easier, the actions I need are directly accessible and it is easy to see which button does what.

 

My IDE of choice for most generic tasks at the moment is Eclipse (mainly Java EE, PDT and RPC/RAP) resulting in my initial though being; “Why doesn’t Eclipse have this yet?!”. So I Googled it and found Bug 507007 in Bugzilla for Eclipse. It mentions that they see an opportunity in adding support for this but the issue appears to be dead in the water for now.

 

A lot of IDEs are build on Java and the touchbar being only available in Objective-C, Swift or any derivative of that makes the step to add touchbar functionality to those IDEs bigger. The same goes for Eclipse.

 

So my first step has been to make the touchbar functions more easily accessible in Java by creating a Java library called JTouchBar that interfaces with a Objective-C++ library through JNI. An initial version of this library is now available on Github under the MIT license. You can check it out at; https://github.com/Nentix/JTouchBar

 

I have whipped up this in a few hours in my spare time (which I do not have much of), so it is still very much a work in progress but it currently will allow you to create a Java application leveraging AWT or SWT which can display labels, buttons and/or scrubbers on the touchbar.

 

Once I have all the features in place that I think are needed to create proper touchbar support for Eclipse I hope to start working on a plugin which will initially support debugging hotkeys.

 

Please let me know in the comments or on Github if you have any suggestions, feedback and/or questions on the library or the Eclipse plugin.

 

Links

♦ Visual Studio Code

♦ JTouchBar