Interactive Brokers' Trader Workstation on Wayland

I need to run Interactive Brokers’ Trader Workstation on Linux on Wayland on HiDPI - a fateful combination. Trader Workstation, now abbreviated as TWS, is a program a client can use to interact with the brokerage services of Interactive Brokers.

TWS is a Java application that is provided for a range of Platforms - Windows, MacOS and Linux, amongst others. However, when you download it for Linux, you’ll quickly notice that it’s a .sh file - an installer program, not a package archive like .deb or .rpm. I’ve tried installing it this way, something that doesn’t feel too right. Thankfully, someone has create an AUR package called ib-tws that does the heavy lifting.

Java

On a side note: I need to mention that I do not enjoy using Java applications on the desktop - they feel a little off visually most of the time, not only when they’re using Swing or Awt, but also with GTK. Maybe its a thing only on Linux where support isn’t prime…? However, in this case, TWS bundles Java - and it is Java 8! Java 8 is from the 2000s, when Java still was a trademark of Sun and hasn’t been bought by Oracle. The latest Java 8 is Java 8u202 and was released January 15, 2019. I wonder what reasons there are for providing an application on such an old platform? There must be some technical debts lurking under the scene that actually are a sign of warning to customers.

Natually, Java 8 is not capabable of running Wayland applications. Java itself doesn’t support Wayland natively, so far, but there are efforts. Efforts on a modern Java, Wayland will never land on Java 8.

Getting TWS to run in Wayland

Anyways, running ib-tws at first yields:

$ /usr/bin/ib-tws

(java:198677): Gdk-CRITICAL **: 14:35:11.303: gdk_x11_display_set_window_scale: \
  assertion 'GDK_IS_X11_DISPLAY (display)' failed
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x000070fc266e81c1, pid=198677, tid=0x000070fbf5b706c0
#
# JRE version: Java(TM) SE Runtime Environment (8.0_202-b08) (build 1.8.0_202-b08)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.202-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libX11.so.6+0x291c1]  XInternAtom+0x41
#
# Core dump written. Default location: /usr/share/ib-tws/jars/core or core.198677
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid198677.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
/usr/bin/ib-tws: line 8: 198677 Aborted                 (core dumped) \
  /usr/share/ib-tws/jre/bin/java -cp \* $JAVA_FLAGS jclient.LoginFrame $IB_CONFIG_DIR

A bit of research made me identify the cause a Wayland vs X11 issue that can be circumvented by running this with GDK_BACKEND=x11 knob. What has the actual problem been? It seems, Java uses GTK bindings for this application, and these bindings then fall back to the real GTK library that determines it should run in Wayland mode - this then somehow lets Java crash. With above knob, TWS starts:

Login screen in TWS - but blurry and pixelated

I ran TWS occasionally, blurry - what can you do, until I found this reddit post “A somewhat hacky way to get nicely scaled X11 apps” that mentions that you can run Xwayland in rootful mode and with hidpi switch and then start single applications in that instance specifically. A bit of research brought up a blog post Run buggy X11 apps with Xwayland rootful mode and Xwayland rootful - part 2 by Olivier Fourdan, who himself works on Xwayland. There’s lots of information in these posts, but finally I also found an AUR package xwayland-run, with which you can run:

GDK_BACKEND=x11 Xwayland-run -decorate -hidpi -- /usr/bin/ib-tws

It starts a new Xwayland session with the options given and forks the program into that session, shutting it all down again when the program stops. Most convenient option so far. I believe the only difference to just starting the app itself is that this Xwayland session does have the -hidpi flag as opposed to the one start sway manages automatically. There seems to be no way to configure the startup flags, neither in sway config, nor through sway-msg.

Caveat

Starting a separate Xwayland session seems to come with a cost: while in regular Xwayland, the clipboard’s shared between Wayland and X11, now its not. I have not found a way to fix this behavior, so far. This is unfortunate, the credentials to login cannot be stored in the application - which is good - and must be entered again at every startup. I have them stored safely in KeepassXC. However, since KeepassXC’s AutoType feature does not work in wayland, I had to copy&paste them into the password fields. That doesn’t work anymore, I have to re-type them every time manually.

Current result

Anyways, I like the look better than before, I just looks cleaner when the app is not pixelated. It may consist of smallish fonts and elements, but one can configure these at least partially to render bigger. Another difference is that additional windows or popups within TWS do not open a Wayland window, they’re just embedded in that one XWayland window.

Final look of TWS on Wayland - sharp and clear (and maybe smallish at times)