X applications on Ubuntu Phone
All the X software
So yeah, Mir... Canonical's very own display server, to replace X server entirely in the future. Just that, all the great software currently existing, is made for X server. Not for Mir. Simple as that. Well, worry not. First of all, you can still put an executable that is written for X server on the phone. As long as it is ARM linux binary, it is a valid one on the Ubuntu Phone as well. True, you cannot just execute it and expect to work auto-magically, but there is quite a lot of ways you can make it work with some extra work. Generally there are 3 major ways to run X applications on the phone:
- Right on the phone via XMir
- Via a compatibility layer called Libertine
- Off the phone but onto the Desktop via SSH with X forwarding
- In the future directly: Ubuntu devs demo gtk apps running in Mir
So Mir is a totally new display server somewhat based on Wayland, but it does come with a layer for compatibility with X. It is called XMir. It is said to be under active development, and expected to be enhanced over time, yet it is already shipped with Ubuntu Touch system on Ubuntu phones and tablets. XMir allows for running X application directly on the phone, inside a full screen XMir context. So you can put a binary compiled for X on the phone, create a launcher for it (.desktop file), add 2 special settings to it, so the phone knows to run it via XMir, and there you go! An X app running on the Ubuntu Phone with Mir!
If you already have your X app inside your phone, you need to make sure that the dedicated launcher contains these few important settings among the standard ones:
X-Ubuntu-Touch=true
X-Ubuntu-XMir-Enable=true
Terminal=false
Type=Application
Then put your launcher to ~/.local/share/applications/ as it does not need setting your root partition to writtable.
And if you need an OSK (on-screen keyboard) in your app, you need two important packages installed in your phone: maliit-inputcontext-gtk3 and maliit-inputcontext-gtk2:
$ sudo mount -o remount,rw /
$ sudo apt-get -q -y install maliit-inputcontext-gtk3 maliit-inputcontext-gtk2
$ sudo mount -o remount,rw /
There are some limitations to this method though. Lots of X applications strongly depend on 3rd party libraries. Some are very standard libraries on Linux for Desktop, being part of default installations. But these will most likely not be present on Ubuntu Phone, especially if they are related to X stack. True, you could try to list every single dependency of your app, find it and install manually. But this can be hectic and maybe not even possible as some libraries might not be available for ARM. You could try to compile everything from source, but that could turn out even more hectic. Your best choice would be to go with this method when your app either doesn't depend on any extra libraries, or you are lucky that all extra libraries are supplied with the application.
Libertine to the rescue
Libertine is, after its info page, "a confined sandbox where you can install deb-packaged X11-based Ubuntu applications have have them run under Unity 8.". Well, you can actually install any X software in it, even not deb-packaged, but that is going into finer detail. To simply put it, Libertine is something you install on your Ubuntu phone, that will allow you to instrall and run X applications. Also, by installing Libertine, you will install a special Scope (you still need to enable it from the scopes list), which will show all your X applications installed inside Libertine as icons, that you just click on, and the corresponding app will just open on your phone via XMir, all automatically. Again, if you'd like to be more technical about it, the aforementioned scope would actually list not applications inside Libertine, but Launchers (.desktop files). So whatever you install inside Libertine, you also need to have a corresponding launcher to have it enlisted within Libertine's scope.
Now, a bit more directly. But also more technically. Libertine is a container. Currently both chroot and LXC modes are supported. So the approach is to actually create a jail environment and install X software into that jail, then have an integrated scope that lists apps from that jail and via clicking an icon, launches corresponding one (ie. sudo chroot ... some_app) inside XMir session.
One characteristic of Libertine is, that the container is running exactly the same distribution of Ubuntu as the host. Libertine makers see this as an advantage for ensuring maximal compatibility. In my opinion, however, it gives far more elasticity if you could run anything you like inside a container. And you can, because your Ubuntu Phone is just a normal Ubuntu, and you can simply create your very own container (ie. using debootstrap) and put any distribution you like into it. You can also create launchers directly into your phone, so your contained app can be listed with native apps, rather then on a dedicated scope. Or, if you are scope developer, you can create your own scope to go with your own container. The bottom line is, if you are not the type of guy who likes DIY, you can just enjoy Libertine as a ready solution.
If you'd like to know about hand-crafting your own container and launching its X applications on the phone, be on the lookout for my future Article "Easy containers on Ubuntu Touch with qemu-debootstrap".
SSH with X Forwarding
This feature is absolutely mind-blowing. Just in case you are reading it without understanding what it means: X forwarding means, that after you connect from one Linux host to another, over SSH, you can run X application on a remote host in such a way, that it will render into your local screen, and will accept your locally connected mouse and keyboard as an input. Imagine you have Firefox installed inside your phone. Then you connect to your phone from your Ubuntu desktop over SSH. Then, inside the SSH session, you execute Firefox, and it appears on your Desktop! Just that, it actually is running inside your phone! a little bit like a remote desktop, just that instead of opening an entire remote desktop in a local window, you are only remotely displaying the application (all of its windows).
If you already are familiar with X forwarding over SSH, here is something you might not have thought about: Although Ubuntu Phone runs on Mir and lacks X stack, but if you are connected over SSH with X forwarding, you are basically making your local X stack available remotely to your phone. So an X application installed inside your phone, suddenly gets X stack to run against. This is actually a HUGE deal! It means, that you can install and carry on you a ineptitude of software that you access in a remote fashion on a Linux Desktop at home or work. You travel from one location to another, and your entire software stack travels with you, in your phone. Once you get seated in front of your Desktop, you just connect witlessly, and run your programs off your phone onto your desktop's big screen monitor. Also, you get to use your desktop's mouse and keyboard, instead of trying your best with the phone's on-screen touch keyboard. This means, that you can enjoy applications that have UI not suitable for small (physically) screens or touch interaction with the user. Even though it is possible to run Thunderbird directly on the screen of your Ubuntu Phone, but it will be a hassle to use tiny buttons, read tiny fonts, scroll with tiny scrollbars, or type with the OSK (on-screen keyboard). But given that you do have Linux Desktop anyways, this is where you are consuming your apps. The magical detail is, that they are actually running inside your phone, which is traveling with you wherever you go!
Read more in my article Ubuntu Phone and X Forwarding over SSH as an ultimate Phone and Desktop integration.
Proof of concept
Time to show you some working example. Here, just for demo purpose, a VERY simple GTK application written in Lazarus. Actually, I designed and wrote this small demo in Lazarus running in my Ubuntu Phone, but I did it using SSH with X forwarding, for convenience, so I was working on my Ubuntu Desktop screen:
I actually have Lazarus installed inside a chroot jail on the phone, which internally runs Ubuntu 14.04:
And then the Lazarus from my Ubuntu Phone came up on my Ubuntu Desktop screen:
I even can compile and run the demo app over SSH session:
So as you can see, the demo is a simple form that prints out some metrics, and has a button, which if you click it, will show a message from the edit field above in a popup window.
Also notice, that the screen DPI is shown as 96, which is true for the screen I am using, but unfortunately the very same DPI is detected when I run this demo app on the phone's screen. This means that I will not be able to use Lazarus automatic HighDPI resizing. Perhaps it is the XMir that lies to the application about the actual DPI, but for now, we will not be taking care of that, as this is only a proof of concept that X app can run on the phone, and not discussion about UI.
Next step was to copy the binary file demo out from the container and directly under the Phone's ~/.local/xmir/demo/demo, a location I chose arbitrarily, you could choose whatever else.
We will also need a launcher if we want to be able to see the app icon among phone's apps, so here is how my ~/.local/xmir/demo/demo.desktop launcher looks like (I have it in the same folder but I will make a link):
[Desktop Entry]
Name=LazarusApp Demo
Comment=Lazarus developed app, made to run via xmir
X-Ubuntu-Touch=true
X-Ubuntu-XMir-Enable=true
Exec=/home/phablet/.local/xmir/demo/demo.sh /home/phablet/.local/xmir/demo/demo
Icon=/home/phablet/.local/xmir/demo/demo.png
Terminal=false
Type=Application
export QT_IM_MOUDULE=maliitphablet
export GTK_IM_MODULE=maliitphablet
export QT_DEVICE_PIXEL_RATIO=
exec $@
the variable QT_DEVICE_PIXEL_RATIO is something I found on lazarus forum, someone claimed it can mess the OSK if it was set to anything, so I just unset it as a precaution.
Now, I need to create a symbolic link of the launcher so it can go to a place where the phone looks for applications:
$ ln -s /home/phablet/.local/xmir/demo/demo.desktop
/home/phablet/.local/share/applications/demo.desktop
now the app will be listed on the phone, in my case next to the Libertine icon (sometimes in order to refresh the Apps scope, you need to use Search feature and type in the name of your app):
Even the OSK works well:
And this demo works so well, because as a Lazarus application, it is a self-contained executable, it needs not to link to any external libraries other than default X and GTK stacks which XMir emulates. As long as your own app is either self-contained, or you are able to supply on dependencies along, you will be same successful running it on the Ubuntu Phone!
Well, there are few drawbacks. One is that there is no windows manager when running X apps inside XMir. Perhaps this will get added in the future. For now this is being handled by Libertine, where matchbox window manager is being used. If you could install some lightweight X window manager inside the Ubuntu phone directly, then you should be also able to use it in XMir, but this is something I have not yet tried. If you are the developer, then things are easier, because you may create your own window decorations, and not depend on the system-supplied ones.
Another drawback is that you really only want X apps that are self-contained and can entirely be deployed somewhere under your home directory. Awfully lots of available X applications aren't like that. They depend on ability to install themselves and save their additional data files under various places of the filesystem outside of the home directory. On Ubuntu Touch devices, the root partition is both space-limited and read-only. Also, as of now, things you add to it, are not persistent between firmware updates. The things you keep under your home directory, however, are. Here again, Libertine has an advantage of actually keeping a chroot/LXC jail under home directory and then moving everything into that jail. But you are free to make your very own container, like debootstrap, and then you can deploy your app into there, while still being able to run it locally on the phone's screen via XMir. The difference is, however, that the chroot jail is isolated from your host, and thus, some things you won't be able to do, at least, not in an easy way. For example, if you run your app directly, you can, say, launch the native camera app programatically.
Well, there are few drawbacks. One is that there is no windows manager when running X apps inside XMir. Perhaps this will get added in the future. For now this is being handled by Libertine, where matchbox window manager is being used. If you could install some lightweight X window manager inside the Ubuntu phone directly, then you should be also able to use it in XMir, but this is something I have not yet tried. If you are the developer, then things are easier, because you may create your own window decorations, and not depend on the system-supplied ones.
Another drawback is that you really only want X apps that are self-contained and can entirely be deployed somewhere under your home directory. Awfully lots of available X applications aren't like that. They depend on ability to install themselves and save their additional data files under various places of the filesystem outside of the home directory. On Ubuntu Touch devices, the root partition is both space-limited and read-only. Also, as of now, things you add to it, are not persistent between firmware updates. The things you keep under your home directory, however, are. Here again, Libertine has an advantage of actually keeping a chroot/LXC jail under home directory and then moving everything into that jail. But you are free to make your very own container, like debootstrap, and then you can deploy your app into there, while still being able to run it locally on the phone's screen via XMir. The difference is, however, that the chroot jail is isolated from your host, and thus, some things you won't be able to do, at least, not in an easy way. For example, if you run your app directly, you can, say, launch the native camera app programatically.
If you want to conduct your own experiment, then you can download files of this particular demo from my google drive here: demo-gtk-for-ubuntu-phone.7z
If you are interested in Lazarus development, stay on the lookout for my upcoming article Lazarus development for Ubuntu Phone.
Hi Kris, what a nice job ! Thanks a lot for sharing this.
ReplyDeleteOn my BQ4.5 I have successfully managed to run Firefox with a xenial container. It runs quiet well via SSH.
Moreover it can run outside the container after having copied some lib files. Unfortunately it doesn't start via the app icon created under the main Scope. Any idea why ?
I will probably play later with some more simple app. to investigate what could be the issue.
Thanks again for your input.
Patrice
Hi Patrice! maybe the launcher is not exwcutable? It then would not show up in the Apps acope. Maybe something about the content about the launcher, coupd you pastebin it here? Finally, perhaps it is about some feature of the ff that does not work under Xmir n which case different (older) ff or chromium should work instead.
DeleteThe need to use Firefox was just to be able to use Sync feature. In my case, Libertine has a bug with FF - OSB disappear in password field while signing in FF account. Same issue via SSH. Even after having the lines about maliitphablet in launcher. May be I will return to Xmarks if it works, not tested via Libertine.
DeleteHere is my launcher used for FF, executable : at launch under Xmir a black window named Firefox opens well, then crashes, nothing found yet in logs...
> vi ~/bin/Firefox/firefox.desktop
[Desktop Entry]
Name=Firefox
Comment=Firefox app, made to run via xmir
X-Ubuntu-Touch=true
X-Ubuntu-XMir-Enable=true
Exec=/home/phablet/bin/Firefox/firefox.sh /home/phablet/bin/Firefox/firefox
Icon=/home/phablet/bin/Firefox/firefox.png
Terminal=false
Type=Application
vi ~/bin/Firefox/firefox.sh
export QT_IM_MOUDULE=maliitphablet
export GTK_IM_MODULE=maliitphablet
export QT_DEVICE_PIXEL_RATIO=
exec $@
And via SSH, the command
phablet@ubuntu-phablet:~$ /home/phablet/bin/Firefox/firefox.sh /home/phablet/bin/Firefox/firefox
opens FF under X.
Thx Kris.
Hi,
ReplyDeleteNice article and very well explained.
Did you try the same with a Java app? Unfortunately the above method doesn't seem to work with my test on Java and Ubuntu Touch.
I cannot get the OSK appear.
Thank you.