Android X server

For the past few months I’ve been implementing an X11 server to run natively under Android. In the near future I may have need for a serializable user interface, so to get a better understanding of how they work I decided to implement the de facto standard, X11.

Well, it turns out the X protocol is bigger than I thought, but through sheer bloody-mindedness I got it finished. And it might actually be useful.

I had assumed that all internet-enabled smartphones would be sitting behind NAT-ing routers, both for security reasons and to conserve IPv4 addresses. But no, on the “3” network in Australia at least, phones all have externally-accessible IP addresses, meaning they can run servers. So you could potentially launch a Linux X application out in the cloud and have it display on your phone.

The user interface is fairly simple: touch the screen to move the pointer, and use the directional pad to activate the left/middle/right buttons. Update: the volume up/down buttons now work as mouse left/right buttons. Both virtual and physical keyboards are supported.

The source code is available at http://code.google.com/p/android-xserver/ https://github.com/mattkwan/android-xserver/ under an MIT licence, and the application (called X Server) is available for free through the Android Market Play Store.

There are a few parts of the X protocol it doesn’t implement …

  • Dynamic colourmaps. Android only supports a 24-bit static colourmap.
  • Dashed lines, tiles, and stipples. There’s no native support for these in Android, and seriously, does anyone use them?
  • Drawing operations other than Copy and Xor. That’s all Android supports.
  • Queueing keyboard and pointer events during grabs.
  • Most extensions. XGE, XTEST, BigRequests, and Shape are implemented, bit that’s it. There are hooks provided in the code, so if you’re feeling ambitious, try implementing some others. Quite a few applications use them.
  • Key click, auto-repeat, and keyboard LEDs.

The server also ships without a window manager, which is a problem because a number of applications expect one to be running. The code includes a parameter specifying an Android service to be launched once the X server is running, and this is intended to start a window manager. But first someone will have to implement a window manager in Android, and doing that properly requires a re-implementation Xlib. Not me, I’m afraid.

However, there is a workaround. Because access control is disabled by default, you can run a window manager remotely, e.g. fvwm -d xxx.xxx.xxx.xxx:0. Not very efficient in terms of network traffic, but it works.


206 Comments on “Android X server”

  1. sam says:

    So why not integrate that with all the goodness of Ubuntu, on a tablet, like say the ASUS transformer prime?

  2. csh says:

    Cool. Must have been quite a bit of work. How did you build xeyes etc.? Which X11 header files and libraries did you use?

    • csh says:

      Sorry, now I get it, you launched the applications from a Linux box and had them displayed on your phone’s X server. Should have read more carefully… Thought you had them running natively on your phone. Would that be possible at all? Probably you’d have to port all the X development libraries to android?

      • mattkwan says:

        You could run applications on the phone, but you’d have to implement the X protocol from the client side, which means porting Xlib.

      • robsku says:

        I don’t see it as a problem, as the client library doesn’t need to be designed to use any OS specific code – in fact it would be stupid, which is why you can run applications from remote servers via SSH connection using X piping – that’s why you can run X Window applications from any Unix, Linux, Windows (usually meaning cygwin applications, but it’s dead simple to write regular Windows application for X Windows – in case of non-C language you’d just write a pure Perl, Tcl, Python, or in this case Java port of xlib (that’s the only needed if you don’t need opengl, compositing, or some other special functionality). With java it should be written as class file xlib.java, and you could use it for both, Java and Android applications for X Windows server, and you could distribute it simply as gzipped .java file (xlib.java.gz). AND I’m willing to bet there’s someone who has written a pure Java implementation of xlib – even though Java is based on same code working under any OS, so you write Java GUI app and the Java VM is compiled to use xlib on Unix/Linux, on Windows the Windows GUI libraries, and same with OS/2, BeOS, etc.

        Anyway I guess some method of reading from X Server app, or defining otherwise a DISPLAY variable to use, although as you unlikely run more than one X session (although I have two X server apps, this and XDSL X Server, so I could run two at time, if I had any sane reason for that in Android), so maybe xlib.java should check if there’s environment variable DISPLAY, and if not just default to localhost::0.

        Hell, I might write it, and libGL.java at that just as well if nobody really hasn’t written them when I feel like now could be fun to do it – I’ve already started plain Perl xlib module to allow shipping Perl X applications without need to provide such app without need to install similar module which needs to have C compiler for installing module combining official xlib C library linked to Perl module. In fact it’s fully possible to write shell script, bash or even plain Bourne shell, even though one has to know all black magic methods of Bourne shell – just like I proved that fixed point decimal math routines, including most complex mathematical functions, like trigonometry, etc. is fully possible, as with any Turing compliant language, even with language that’s only math support are three logical expressions, AND, OR and NOT (from those you can build all the rest, but these three are all the essential ones, and inside circuit boards, like CPU’s, all mathematical operations are done with them – even if there’s also XOR, NAND, NOR, etc., they just perform with one operation what can be done with right combination of two or more of those three – but I’m rambling to emphasize that xlib class in Java for Dalvik (or ART on newer Android versions) is piece of cake really – the X server is way harder, needing a very OS specific implementation, and it’s more complex implementation of the functionality of X server than port as used for just porting the code straight to simply in syntax of target language – for example reading, and following the commands from client application and how to write all kinds of stuff – not just because with java you need to implement confusing combination of classes that would be extremely confusing to try and study how this or that was done with the C code of X server as reference point, as following the C code, then trying to follow same part in Java, the first thing you’d note is that it’s not possible, and your better without the X.org code and instead learn the specs on how X should work inside, and see how it’s implemented…
        The point being that I’m baffled of why didn’t the author wrote such class, as it would be stupid easy for person who wrote the server already…

  3. Congyin Shi says:

    Great! I like it. BTW, are you using the native linux framebuffer? Or you translate it to Android graphic API?

    • mattkwan says:

      All the X commands are implemented using the Android API.

    • robsku says:

      Correct me if I’m wrong, but I don’t see any point why Android would create even single virtual console, as there’s no point because you can’t switch between them and framebuffer is initiated on beginning of boot sequence, and it’s enough to run Android GUI, like if you made Linux boot sequence to start X for framebuffer (Xfb) and removed the creation of VT’s (6 by default) – that would prevent you from using framebuffer, and I think Android GUI is run that way, so you must draw using it’s methods – I’ve never heard of it being possible to draw “past” it, but correct me if I’m that badly wrong!

  4. nibheis says:

    Hi! Thank a lot for this sw and the apk on market.

    I installed from the market, and here are my results:
    – no pb running basic X11 apps (xeyes, xterm)
    – good interface for text input (better than xvnc)

    The problems I found were:
    – I could not launch twm:
    * twm launched after an xterm: no border on xterm, unusable twm window
    * twm launched first: unusable twm window. Then, for any new window, I get the twm window placement (kind of wireframe for the new window), but I can’t click to make the window appear.
    – more complex applications would not launch completely (e.g. mysql-workbench)

    Regards

    • mattkwan says:

      It only makes sense to launch a window manager before running applications, so I’m not surprised launching xterm first caused problems.

      When you launch an application after twm is running, you’ll get a wireframe outline that you can move around. Click the trackpad button (equivalent to left mouse button) to make it appear.

      I don’t know why the twm window is unusable – I encountered the same problem myself. It should be populated with a menu, but no X commands are issued to write the menu text, so I don’t know what’s happening. I don’t have time to go through the twm source code.

      I suspect the reason more complex applications don’t work is because twm isn’t ICCCM-compliant (see here). Compliant window managers are expected to set certain properties on managed windows, and when they don’t exist a lot of applications abort.

      • nibheis says:

        I agree, it’s better to launch a window manager first! On my desktop, when the window manager is killed or crashes, applications still live on their own, and I can start new applications without any problem. Then, when I restart the WM, all windows get their decorations back.
        So I was just wondering why I could not just do the same with your x server for android.

        I’m used to twm, and so far I cannot click left to make the window appear when the wireframe outline is displayed (I’m using a lenovo tablet with keyboard and mouse). I can move the wireframe with my fingers, I can click using the mouse (or by finger tapping on the screen), but I see no result: the wireframe stays on the screen linked to the x cursor.

        My other questions are:
        – how can I right click? I know that Android “transforms” my mouse right click into a “menu” key before it reaches the application… but maybe there is a trick on your side to emulate a right click?
        – What are the current limitations? I mean, if i can get twm running, can I start any kind of application?

      • mattkwan says:

        I’ve assigned the mouse pointer buttons to the Android trackpad. Trackpad left and middle = mouse left; trackpad up = mouse middle; trackpad right = mouse right. You could test it with a simple program like xmessage and try to click the OK button (without twm running).

        I didn’t realize you could connect a mouse to an Android device. If you know the keycodes that the mouse buttons generate I can modify the server to handle them.

        Regards,

        mkwan

  5. Simon E. says:

    Just a reminder, you can run a Linux distro in a chroot on the device itself and connect to the Xserver.
    For instructions on setting up a chroot, see here: http://www.nerd65536.com/2011/07/installing-ubuntu-in-android-version-2.html

  6. Wolf says:

    TWM runs OK, xeyes and xlogo run OK, but xterm causes it to lock up (until I kill xterm, in which case it comes back to life). HTC Desire, Cyanogenmod 7.

    • mattkwan says:

      I’ve noticed that xterm takes a while to start, but the delay occurs before it open a connection to the server. I’ve never seen it lock up, though.

      • Wolf says:

        Also, you may be interested to know that this can be repackaged as a .BAR and deployed successfully to a blackberry playbook, where it runs under the Linux virtualisation layer. It appears to work fine. The lag time of initial display of apps is longer, and I can’t click anywhere because I don’t think the playbook has any way of emulating the functionality of the trackball.

        If you wish me to provide the signed BAR file I created, or take screenshots, let me know.

      • mattkwan says:

        Would it be possible to link to your BAR file? I suspect I’ll be putting out a few new releases as people report issues, and since I can’t update the BAR file myself it would be best if I kept it at arm’s length. You could also put up a screen shots on the page where you host it.

        On the subject of the trackpad, quite a few people have mentioned that many new devices (especially pads) don’t have one. So what physical keys are available? The next release will recognize the volume up/down buttons as mouse left/right, but that doesn’t cater for mouse-middle unfortunately. Do all Android devices have physical volume controls?

  7. mmullin says:

    How do I install this?

  8. John Carter says:

    Can you make the apk also available in the download section of http://code.google.com/p/android-xserver/ ? Not all android users use the android market…

    Thanks

  9. Numan says:

    I want to take screen snapshot from android tablet. But xwd, import snapshot apps doesnt work.
    How can i get a snapshot?

  10. […] uma IDE e um servidor X (sobre), é cada vez mais possível trocar um desktop por um Android; além disso, tem sempre novidades  […]

  11. nate-m says:

    If you have a rooted Android phone it’s possible to run a ARM Debian environment in a chroot on Android. You just have a partition on your SD card formatted to be Ext3 and then either copy a existing ARM Debian installation to it or run debootstrap to make a new one.

    Then you can install your GUI applications there.

    Hopefully with this application it makes it possible to have something approaching a Linux desktop experience on your android phone. With the ability to install and use any application on your android phone that is available in the Debian ARM repositories.

    • bd1234567 says:

      I’ve been able to do this and xclock, xeyes run fine through the XServer when DISPLAY is set to 127.0.0.1:0. I’ve also found that ffplay works for playing mp4 files! Its a bit slow though (1fps) on my phone (1ghz xperia arc). I’m not sure if the slowness is due to the ffplay being a non-bionic libc or if its from the java based xserver not pushing frames to the screen fast enough. If its the latter, maybe parts of this could be optimized with JNI? Just a thought.

      Working on getting fvwm and seeing how well it works as a window manager. Awesome project!

      • mattkwan says:

        I suspect the slow frame rate is due to bandwidth. The server only implements the bare-bones X protocol, so all the frames would be rendered with PutImage, which uses uncompressed images.

  12. markstinson says:

    Have you taken a look at WeirdX http://www.jcraft.com/weirdx/ – it even supports eSound. jcraft.com has several Java “Unicie” applications which could be ported to Android.

  13. Steve J says:

    Even if most mobile phones around the world are NATed today, I would hope that most Android handsets are going to eventually get IPv6 straight from their carriers or wifi providers. In other words, projects like these are great to get off the ground now so that in the new, flatter world they will be mature and provide some real value.

    Great job!

  14. John says:

    cool.
    and i assume nat is not a problem when you can ssh out to establish your X tunnel: ssh xterm
    is there a faster/better droid emulator than the linux one in the android sdk?

  15. Adam Bliss says:

    This is really useful! There’s no need to port Xlib or use a remote host. I use a native android terminal emulator to chroot into a full debian install on my tablet (a bluetooth keyboard helps). Now with “export DISPLAY=127.0.0.1:0” I can finally run graphical apps and not just vt100 apps.

    • Daniel Landau says:

      When I try to run graphical apps from a chrooted environment, I get “Client is not authorized to connect to Server”. What to do?

  16. Jiang says:

    Thanks for this project. I have a (ARM) build of Xlib and fluxbox, which kinda-sorta work using this X server: http://i42.tinypic.com/2utgca1.png
    You could find them in the BotBrew project (just ask Google).

  17. […] man from Melbourne called Matt Kwan has been spending his time getting an X server to run Android. The main sticking point is the lack of a window manager in Android, which requires a […]

  18. Ken Thomas says:

    Thank you! There was another X project for Android, which looks abandoned– if you don’t know. I’ve been playing around with the idea myself because I’d like Xdmx & xpra on Android (especially if the wearable google-googgles pan out). May be interested in supporting or collaborating.

    Best,

  19. MikeCamel says:

    When I try to run fvwm, I things start up, and then I get an error “fvwm-themes-root: not found”. Any ideas? twm also works, but I’ve been unable to do anything much with it, sadly.

    • mattkwan says:

      When I launch fvwm I get a whole lot of errors relating to request code 20, but it comes up ok on my phone. And once it’s running I can launch gnomine and complete a whole game. I’m using the Fedora 16 fvwm RPM. Commands were …

      fvwm -d 192.168.2.171:0 &
      env DISPLAY=192.168.2.171:0 gnomine

  20. vvi says:

    Bug: trying to start gedit (or so) turn touchscreen in no touching mode.

    • Kirn Gill says:

      Use the volume control hardware keys (if your device has them) to click. If your device does not have volume control rocker keys, you’re pretty much screwed.

      • vvi says:

        I said about another problem (even this persist, I have no HW VOL+- keys). After some things (for example, running gedit) my touchscreen come out of work. It doesn’t work anyway. Neigher in X-server, nor in other android apps, including settings. Only full restart return it to work.

  21. DreitTheDragon says:

    If I get it, then now I can run apps on PC and use them on Android phone same as with “ssh -X”? I mean that I want to run GIMP or Inkscape on that and try to draw something – is it (even theoretically) possible? It should be nice captitive drawing tablet for poor people 🙂 I tried it with VNC viewer, but this looks much better. You’re great! 😉

    • Rainer says:

      For tunneling via ssh you need something like this:
      “-R 6011:localhost:6000”
      Then “export DISPLAY=:11.0”
      Where can I install the fonts?
      You don’t need a local libx11 for a local windowmanager, but it would make the work very hard if you don’t have it (native calls through sockets).
      Does this X server support a multicore cpu?
      Whatever: nice work!

      • mattkwan says:

        Font support is minimal – just the built-in Android serif, sans-serif, and fixed-width fonts – because Android uses a different font naming convention.
        For a local window manager, native calls through sockets would be at least as much work as re-implementing Xlib, plus you couldn’t re-use an off-the-shelf manager.
        Each client gets it own thread, and Android seems to use separate threads for rendering graphics and handling input events, so it might take advantage of multiple core. But that’s handled at the OS level.

    • Yes I am also longing to try out “gimp-with the finger-tips” and from my research so far it seems absolutely possible. For the time being I am researching the possibilities to use virtual trackball (app) as substitution for the lacking mouse click possibilities on tablet. And than just activate gimp from the terminal as described in the threat. This is so cool

      /Mikkel

  22. […] non fa altro che riprendere quanto scritto in questo post dall’autore del software, Matt Kwan, dottorando di ricerca presso la RMIT University di […]

  23. […] Прeдcтaвлeн прoeкт Android X server , в рaмкaх кoтoрoгo пoдгoтoвлeнa рeaлизaция X11-ceрвeрa для плaтфoрмы Android, нaпиcaннoгo нa языкe Java. X-ceрвeр выпoлняeтcя кaк пoдклacc Android View, чтo пoзвoляeт лeгкo интeгрирoвaть eгo в другиe прилoжeния. Кoд прoeктa рacпрocтрaняeтcя в рaмкaх лицeнзии MIT. Интeрecнo, чтo рaбoтa зa нecкoлькo мecяцeв выпoлнeнa acпирaнтoм, пoжeлaвшим нa прaктикe рaзoбрaтьcя в тoнкocтях рaбoты прoтoкoлa X11. Рaбoты oкaзaлocь бoльшe чeм прeдпoлaгaлocь, нo прoeкт пoлучилcя вocтрeбoвaнным и пoлeзным, пoэтoму был в итoгe дoвeдён дo кoнцa. […]

  24. Kirn Gill says:

    Almost every X11 app I have ever used on X.org has ran perfectly fine without a window manager. That’s something you might want to look into.

    Also, a window manager, ‘matwm2’, that a friend of mine wrote, has issues with your X server. I’d like to detail them but I’m not too technical on X stuffs.

    Actually, I think X apps would work better with an older version of Xlib. Maybe the one from X11R6.6 might be of use (but it’s fifteen years old, so that might introduce different issues not related to your X11 implementation).

    But continue the good work! And good to see that you are pushing frequent updates to Play Store (new name for Android Market), and that you publish the .apk files for anyone that does not have (working) access to Play Store.

    You might want to consider publishing to Applanet or Aptoide 🙂

    • mattkwan says:

      The window manager issue turned out to be a bug in my implementation of GetProperty, fixed in version 1.05.
      I’d be interested to see the matwm2 issues, especially an X errors it encounters.

      • segin2010 says:

        Well, ‘matwm2′ doesn’t display ANY of it’s standard window controls on the window frame. Nor does the window title text appear. I’m using a purely default setup for matwm2, and by default, the XLFD it asks for is just “fixed”. Although it has support for XFT, my “clients host” is an old iMac running Mac OS X 10.3.9, and the old X11 stuff it has doesn’t provide XFT. Oh well.

        The only complaint I see on the commandline is that the “SHAPE” extension is missing. Who cares?

        Attempting to take ‘xwd’ dumps of the root window returns… the root window. Without any of the obscuring children. Which amounts to dumping whatever the wallpaper is. Oh, it beeps twice during the process. Using the -screen argument just turns the cursor into a weird cross and makes the mouse cursor unable to interact with anything.

        Using -xy to ‘xwd’, like so, causes the server to beep once, hang, and eventually ANR: xwd -root -xy -out xman2.xwd -display 192.168.2.109:0.0

        By the way, I’ve been testing with 1.05 all along. Here’s the stderr from xterm “XFree86 4.2.99.903(174)”:

        X Error of failed request: BadValue (integer parameter out of range for operation)
        Major opcode of failed request: 12 (X_ConfigureWindow)
        Value in failed request: 0×0
        Serial number of failed request: 49
        Current serial number in output stream: 50

        If you want to play with ‘matwm2′ yourself… http://www.squidjam.com/matwm/ is the main page, and the svn is at http://segin-utils.googlecode.com/svn/trunk/matwm2/
        Hope this hopes iron out some kinks. Feel free to email me at segin2005@gmail.com if you have more questions.

  25. Bøgeskov says:

    I really like this project. Unfortunately I’m unfamiliar with Java (It would be possible to become familiar with it, but it would take some time, several weeks, given my current schedule), so I won’t be useful in development, however I’ve tried it and come across a couple of issues.

    I’m sitting on a Transformer and would really like to use my arrow keys, however I don’t know if its by design or “feature” but left does Button 1, right: Button 3, both Up and Down: Button 2. Trying to navigate an xterm produces a lot of pasting ;-). If it’s by design, could a preference switch be made to give the other output.

    I tried to use xmodmap to get Control & Alt to do as I feel comfortable with, however every time I used xmodmap my keyboard got really messed up. It looks like the last entry in the xmodmap “keycode” list is the only one that survives according to “xmodmap -pke”

    I’ve installed a debian chroot, which seems to work perfectly but the transformer doesn’t have an Escape button, this makes using vi difficult, and missing control/alt/meta binding makes me think that installing emacs wouldn’t be worth the download time.

    Tell me what I can do to  help get move this project forward.

    • mattkwan says:

      I mapped the mouse buttons to the directional pad because they’re the only suitable hard keys on most phones.
      Don’t expect anything too sophisticated on the keyboard front. Android only added proper keyboard support in release 3.0, and if I go to that release it will be incompatible with most phones. Unfortunately Android pre-3.0 has no concept of a Control or Escape key.

  26. vvi says:

    10.03 version looks much better. Even gtk2-app CAN start. Anyway, it is a great mouse problem. My device (and may be not only my) has no hardware volume buttons. So, if it is possible, can you make buttons configurable? There are only “Menu” and “Back” HW buttons (home also, but I don’t know if it can be reconfigured), but I can plug HW keyboard to remap more buttons.

  27. PhilM says:

    Great Work, thx! have it running with local chroot Debian on android 4.02 (nexus Galaxy). Since i use a full bluetoth keyboard/touchpad i have probs with these funny kb twist and would like an optional straight forward plain vanilla standard Mouse/KB implementation 😉
    For now i can move the mouse pointer, pressing mouse button even positions cross cursor. Tab or Return keys are not working.

    • mattkwan says:

      The problem is, Android has only supported full keyboards since 3.0, so if I add full keyboard support it will become inconmpatible with 2.x – i.e. all the smartphones. Also, I don’t own a tablet, so I’d have no way to test it.
      I’ve discovered it’s pretty much impossible to write applications that work across all Android devices. There’s to much variability.

  28. Kirn Gill says:

    Well, ‘matwm2’ doesn’t display ANY of it’s standard window controls on the window frame. Nor does the window title text appear. I’m using a purely default setup for matwm2, and by default, the XLFD it asks for is just “fixed”. Although it has support for XFT, my “clients host” is an old iMac running Mac OS X 10.3.9, and the old X11 stuff it has doesn’t provide XFT. Oh well.

    The only complaint I see on the commandline is that the “SHAPE” extension is missing. Who cares?

    Attempting to take ‘xwd’ dumps of the root window returns… the root window. Without any of the obscuring children. Which amounts to dumping whatever the wallpaper is. Oh, it beeps twice during the process. Using the -screen argument just turns the cursor into a weird cross and makes the mouse cursor unable to interact with anything.

    Using -xy to ‘xwd’, like so, causes the server to beep once, hang, and eventually ANR: xwd -root -xy -out xman2.xwd -display 192.168.2.109:0.0

    By the way, I’ve been testing with 1.05 all along. Here’s the stderr from xterm “XFree86 4.2.99.903(174)”:

    X Error of failed request: BadValue (integer parameter out of range for operation)
    Major opcode of failed request: 12 (X_ConfigureWindow)
    Value in failed request: 0x0
    Serial number of failed request: 49
    Current serial number in output stream: 50

    If you want to play with ‘matwm2’ yourself… http://www.squidjam.com/matwm/ is the main page, and the svn is at http://segin-utils.googlecode.com/svn/trunk/matwm2/

    Hope this hopes iron out some kinks. Feel free to email me at segin2005@gmail.com if you have more questions.

  29. dreitthedragon says:

    Just one question (again)

    When I’m using “Linux installer” (running Debian, everything works), which commands I must write to be able to use your Xserver? I think it’s possible, but I can’t organize my thoughts and I’m not so good with those forwarding things 😦

    • mattkwan says:

      It’s a bit unclear where you’re trying to run the X server. Normally you just launch it by tapping on its icon in the applications menu.

      To make a Linux X application run on the server, first get the phone’s IP address from the “IP address” menu in the X server. Let’s say it’s 192.168.2.171
      Then you can run an application such as gnomine with –
      env DISPLAY=192.168.2.171:0 gnomine

      Old X applications let you set the display as a command-line option, e.g.
      xeyes -display 192.168.2.171:0

  30. David says:

    Hi,

    I was just wondering if you could help me get up and running/clarify if what I think I can use this for is accurate!

    What i’d like to do is ssh from my android device to a remote linux machine and then run x11 programs on the remote machine which open x11 windows on my android device.
    Is this correct?

    If so how do I achieve this? I’m using connectbot for ssh. I’ve tried setting up port forwarding on the ssh connection, but i’m not sure if i’ve done this correctly and if so what i need to do about setting the DISPLAY variable on the remote machine?

    Thanks for any help, this could prove to be very useful!

    • mattkwan says:

      That should work, but the tricky part is getting both connectbot and the X server running simultaneously.
      The first step is to determine your phone’s IP address. The X server has a menu that provides this information. Let’s say it’s 192.168.0.2
      On the linux machine you run a command using either the -display 192.168.0.2 option (if supported) or by setting the DISPLAY variable (e.g. env DISPLAY=192.168.0.2)
      That works fine if you type the commands from the desktop, but if you’re using running connectbot on the phone it means you’re probably not running the X server, and the application will have nothing to connect to. In theory you can launch the application in the background, preceded by a sleep command, and quickly log out of connectbot and launch the X server.

      • Rainer says:

        This will not work, if the target system is behind a firewall.
        Also I would recomand to activate accesscontrol by default and to allow only 127.0.0.1 as standard.
        To get it to work through a firewall open a remote port forward from a port bigger than 6000 and set DISPLAY to :[portnumber-6000] befor starting your xterm.

        Connectbot:
        Remoteforward 6013:127.0.0.1:6000

        Then start the X-server

        After that switch back to connectnot and enter
        DISPLAY=:13.0 xterm

    • Ken Thomas says:

      If I understand what you wish to do correctly, Xvnc would be a far smnoother solution.

    • Ken Thomas says:

      See below; see Xvnc.

  31. EeeeKa says:

    Which window managers, and therefore desktop environments can work with this server?

    • mattkwan says:

      Personally I’ve only tested it with twm. It doesn’t support X extensions such as SHAPE or RENDER, so I don’t know how well other window managers will work.

  32. a says:

    How can I use It ?

  33. tt says:

    It doesn’t work for me with connectbot : I have the error
    export DISPLAY=192.168.0.5:0
    xclocks
    Error : can’t open display 192.168.0.5:0
    I tried to see if the x server is reachable but 😦
    telnet 192.168.0.5 6000
    telnet: Unable to connect to remote hosts: connection refused

    • mattkwan says:

      The X server application needs to be running first, launched manually. Otherwise nothing will be listening on port 6000. But if it’s already running you may be having problems with network configuration.

  34. Mohammed Khoory says:

    Great work on the server! I’m hoping this server will mature and ends up being able to run everything that regular xorg can run.

    I’ve tried running fluxbox on my phone’s Debian chroot and it actually works. Stuff draw much faster than the VNC stuff I was using previously. This is great 😀

    A lot of apps seem to expect SHAPE to be implemented. It shouldn’t be that hard to implement. I may take a look at the code sometime if I’m not busy

    • Mohammed Khoory says:

      Also, I think it’s not necessary to implement a window manager just for this. It’s better to focus on just teh server. Window managers can be provided via a Debian chroot, which is actually very easy to set up from the market.

  35. Ronan Klyne says:

    Just leaving a +1 and thanks for the effort you’ve put in. I look forward to tinkering (and maybe patching a thing or two) when I have the time.

  36. sam freed says:

    OK, I have it running on Transformer-Prime, with some loopbacked ubuntu I picked up somewhere…. I will get a proper chroot going soon. (thanks, x74, great code)

    for some reason twm gives me some 20 useless little windows, and fvwm works ok-ish, looks like I have a few pixels wraparound or something. Not to worry.

    For now, the CTRL button gives me keycode 114 keysym 0 – remind we where I fix all that stuff?

    I hope to have a Perfectly Precise Pangolin running on my ASUS soon… Then I can dump my old trusty Lenovo from 5 years ago, and be transformed!

  37. sam freed says:

    I’m running 4.03, is there a way of using newer facilities without 2 distinct executables? I don’t feel like taking responsibility for a fork…

    • mattkwan says:

      I’m afraid a fork might be the only option. Going to 4.0 would make the app incompatible with nearly all the handsets out there. Plus, I don’t have a 4.0 device to develop it on.

  38. sam freed says:

    Ok, lets see – I’m an experienced programmer, with near-0 knowledge of Android. Plenty of Linux experience. Any tutorial/book you can recommend?

    • mattkwan says:

      Android is Java with different user interface libraries. Personally I learned it from Google’s on-line resources at developer.android.com, but there are probably books out there as well.

  39. Myles says:

    This is really cool, I’ve been playing with window managers from here: http://www.junauza.com/2008/08/20-most-nimble-and-simple-x-window.html all morning. Some hits, some misses. One thing that I would like is to change the dpi (resolution, I mean) of the X server. I am getting my apps running ok (monitoring apps, they basically use the display, interaction isn’t really required — so I could really run them withouta window manager at all) but I can’t read them. I would gladly trade screensize for readability. Is there any way to achieve this?

    • mattkwan says:

      On the display side it would be fairly easy. Android lets you specify a transform matrix for all draw operations, so scaling is no problem.
      The main issue is the user interface for specifying the DPI. The value needs to be set before the server comes up, although I suppose you could do a restart of an existing server if you didn’t mind terminating its clients.

  40. Hendrik Boom says:

    What would seem to be wanted to make this even more useful is to configur the thing into an X terminal – the kind of thing they sold about 20 years ago. It would start up with a login box — where you could specify the machine you wanted to log in to, The first thing you would get is an xterm onto that machine, whereupon you could start any window managers you wanted. Perhaps this would be easier to add than an in-app window manager?

    — hendrik

    • mattkwan says:

      Implementing an xterm is a lot of work, but there’s a third-party application called Connectbot that will open ssh/telnet sessions. I’ll try adding a menu option that launches Connectbot (if it’s installed), but it remains to be seen whether the X server will respond while Connectbot is in the foreground.

      • Hendrik Boom says:

        That’s just the point. You don’t need to implement an xterm. What you want to do is to log into the remote system and get it to start an xterm that’s displayed on your X server.

  41. I would find it very inconvenient having to use the volume up and down for the right and left mouse clicks. Do you think it would be possible to use easystroke linux application (Mouse Gestures In Linux) to do the right and left click? As she demonstrate with ubuntu in this video
    http://www.youtube.com/watch?v=W6T8ZQ-r1O4 time: 1:30?

    I have read this entire thread but it’s hard to get/remember everything. Maybe it allready have been covert if so I apologize.

    Lovely Work Thanks.
    /Mikkel

    ++++++++++++
    Packard Bell Liberty Tab G100
    FW: Tegraowners ICS ROM
    Recovery: thor touch recovery 1.7.2
    Debian chroot with: Debian Installer free
    small image.
    ++++++++++++

    • mattkwan says:

      Unfortunately screen touch events can’t be used for mouse clicks because they’re treated as X motion events and sent to the client.

      • Thank you respond. I can see that much of your focus is on android smartphones and I am a tablet user. My tablet does not even have a directional pad. Would it be possible to make some buttons at the bottom of xserver window that could be right-click, left-click? On a tablet screen there will be room for that that.

        /Mikkel

  42. oh wait … maybe one could use a virtual directional pad (virtual d-pad) instead?

    /Mikkel

    • Rainer says:

      Multi touch gestures are also an option.

      • Hmm how is that defferent Mouse Gestures In Linux? Maybe that because it goes on on the android side. Ok as long as I can get going with the virtual d-pad or track ball I am happy. Can’t wait to get my hands on this. Just have someting else to do first.

        /Mikkel

  43. JJ says:

    Would it be possible for you to modify the apk, so that it also enables portrait orientation? I’d like to experiment with it, and run it on a tablet, which makes it very uncomfortable to hold the device landscape.

    • mattkwan says:

      Well, it’s trivial to implement – just change screenOrientation from “landscape” to “portrait” in the AndroidManifest.xml file – but it wouldn’t make sense for most devices (i.e. smartphones). You’re welcome to compile your own version – the source code is freely available,

      • Michael Enke says:

        Submitted new Issue 32, a patch to read from /sdcard/XServer/config
        to decide to start in landscape or portrait.
        One line content:
        orientation=portrait
        And yes, portrait can make sense also on smartphones 🙂

  44. I have got enough of the shape extension implemented for twm, xeyes and oclock to run correctly:

    http://android-xserver.googlecode.com/issues/attachment?aid=50001000&name=Screenshot_2012-05-30-17-46-33.png&token=C–Ka4Xap0qRwzqlI9KQGLWRWVk%3A1338472888102&inline=1

    The code is up as a googlecode clone. If you want to merge the changes just note that I implemented unix domain sockets for improved performance with a chrooted linux, there is a boolean value currently selecting between this code and the original network sockets code).

  45. soltesza says:

    This is great work, keep it up.

    If we had a decent X Server for Android, that would help a LOT for implementing a proper Desktop Mode on Android devices and allow running full-blown Linux applications on Android.

  46. Mikkel says:

    Is there anyone who would advise me here? If I have a debian commando-line environment in a debian chroot on my android tablet what will then advise me to install on top to build up to the android-x-server.

    X.org?

    apt-get install xorg?

    my favorite minimalistic wm?

    apt-get install JWM?

    Or should I drop all these underlying processes and install only the x-applicationen?
    (I wouldn’t mind using the android-x-server without wm if I can make it work)
    apt-get install xrvt?

    Thank you in advance mikkel

    ++++++++++++
    Packard Bell Liberty Tab G100
    Tegraowners ICS ROM Recovery:
    thor touch recovery 1.7.2
    Debian Kit for Android
    ++++++++++++

  47. Curt says:

    Thank you very much this

  48. eckard says:

    Hi Matt
    thx for that work, great!

    I sent a xmessage to the xserver and it is displayed correctly. But it doesn’t execute “okay”-button! The okay-button , the rectangle becomes fat, but no execution. The same with a python-window sent to the xserver. Why doesn’t it execute? – It didn’t start a window mananger – I don’t need it for my affairs. Starting fvwm from a remote machine the buttons of xmessage or python window don’t execute either. Why? I’ve a HTC Desire S Android 2.3.5

    I need a special compilation of xserver with “portrait” orientation and other resolution (dpi) for a special messaging system that sends messages to xservers on PCs (Windows, Linux) and now on android. Can you help me to install a cross compiler an change the values to achive my aim? I would make a donation for this project or simple pay you your efforts, say 50 Euro.

    And I need somewhat sound appearing if a new message appears 🙂

    tia
    Eckard

    • mattkwan says:

      Hi Eckard.

      Not sure if this is the cause, but buttons work a bit differently in this X server. The touch screen can only be used to position the cursor. To execute a button press you need to press the directional pad or the volume key.

      Doing a portrait version is fairly straightforward. In the Android manifest file the screen orientation is explicitly set to “landscape”, so just change that to “portrait” and re-compile. No need for a cross-compiler – it’s all written in Java using Eclipse, so it’s Write Once Run Anywhere (TM).

      As for making a sound, the XBell command is supported, so you can at least make it go beep.

  49. eckard says:

    Thank you, Matt. I’ll find somebody who set up eclipse for me, I don’t know about and have not time for that. Can you say me where to change the dpi ? I need a Xserver with 600 pixel wide in portrait mode. Message windows have exactly these 600 pixel. If some person / enterprise here wants to do that for me, please mail me, I pay! egerlach@aiai.de

    • mattkwan says:

      Forcing a 600 pixel width shouldn’t be too hard. Android lets you specify a transformation matrix for each canvas, so you can use that to scale X Windows coordinates 0-600 to physical coordinates (say) 0-480. The command would be canvas.setScale (480.0 / 600.0, 480.0 / 600.0);
      It think the screen size is explicitly stored in a pair of variables, so you’d have to explicitly set them to 600x??? as well.

      • eckard says:

        Thank you, Matt! I’ve done first tests making the message windows bigger if the receipient is android. It was easier than I thought. Font size is also okay out of the box, no changes of my source code necessary. I think I won’t change the dpi now. I nee XBell now and xserver in portrait mode. Can you say me where to implement XBell? I think I need a window manager (wm) and send the wm a “bell”, right? And the wm sends it to android, right? Or how does it work with android?

        Can you perhaps release a xserver in portrait mode? Or perhaps make your xserver configurable for portrait and landscape in config parameters? 🙂 Apps for the iphone have portrait mode, too. 😉 See Xserver for iphone, the screenshot even shows the portrait mode only:http://itunes.apple.com/de/app/ix11-x-server/id314915946?mt=8 . If XBell works with a wm (i.e. out of the xserver code) I wouldn’t have to recompile the source. That would help me very much. I can make a donation for your university or for somewhat social project in Australia. Or you give the project to somewhat enterprise who sells the xserver app like the app for the iphone.

  50. eckard says:

    Dear mattkwan,
    you didn’t answer so far, I asked whether you release a portrait version. You don’t want to – maybe you have no time? Please answer if you work at a portrait version or not, I want to avoid double work. I’ve found two person who can help me to install Eclipse to compile your source code. Both persons try to achive a working installation, but success is not sure.

    If anyone needs to send a “bell” to mattkwan’s xserver: xkbbell -display 192.168.0.42 -v 100 works on ubuntu and suse out of the box. My android HTC Desire S has WLAN IP 192.168.0.42. You don’t need a window manager (like fvwm) started.

    Eckard

    • mattkwan says:

      Hi Eckard.

      Sorry about the slow response, just getting a few things sorted before I start a new job. I can e-mail you an APK file with a portrait version if you like – the change in the source code is literally one line.

      However, you might want to get Eclipse set up anyway, because I’ll be releasing a new version soon that implements the X shape extension, and you’ll probably want that in portrait mode as well.

      • eckard says:

        Hi Matkawn,
        thank you for your offer. Yes, please send me a apk in portrait mode.
        X shape extension at the moment is not interesting for me because my message system is for practial use and not for look-and-feel. But it may be interesting in future.
        Okay, I’ll try to set up eclipse to be able to compile the code in future.

        Please send me a apk in portrait mode. I’ll distribute it if other users mail me, okay? Please send it to egerlach@aiai.de

        thank you for your work. If you nee a donation mail me now or later when your project grows.
        Eckard

  51. bjrosen says:

    How do you get X forwarding to work with Connectbot? I’ve installed X Server and Connectbot on my Nexus 7. After I’ve sshed into a Linux system I’ve tried setting DISPLAY to 127.0.0.1:0 and also to 192.168.1.157:0 and then I tried to launch XEmacs, I get an X server not responding error.

    Please provide step by step instructions

    • mattkwan says:

      First of all, you’re not doing X forwarding, you’re just using Connectbot to initiate an X client. DISPLAY should be set to the IP address of the Android device.
      If that doesn’t work, try logging in to your Linux system through other means and run the same command. Make sure the Android device is reachable and on the same subnet – try pinging it.

    • Myles says:

      Set the display to 192.168.1.157:0.0 instead. That works for me.

      • bjrosen says:

        Setting DISPLAY to host:0.0 doesn’t work for regular Linux to Linux either. A standard ssh connection (Linux to Linux) sets the DISPLAY to localhost:10.0. Connectbot doesn’t set DISPLAY at all, setting it to localhost:10.0 by hand doesn’t help. SSH on a standard Linux box enables X forwarding by placing the following in the .ssh/config file

        Host *
        ForwardX11 yes
        ForwardX11Trusted yes

        Alternatively ssh can be called with a -X command line argument, how do you do the same with Connectbot?

    • Rainer says:

      You can try this:

      Android X server


      This is simple ssh X-forwarding done by hand.

    • H3g3m0n says:

      Try just starting the xserver, getting into the chroot on your phone (either by connectbot, terminal emulator or a adb shell) then running:
      export DISPLAY=:0
      xcalc

      Worked for me. Unfortunately xfce needs dbus, and fluxbox crashes the xserver app.

  52. steve says:

    I haven’t been able to connect to the X server. I add the the IP of the box I’m trying to run from in the “Access control” tab. When I scan my phone, I see that the port is listening:

    Starting Nmap 5.51.6 ( http://nmap.org ) at 2012-08-28 09:32 EDT
    Nmap scan report for 192.168.1.144
    Host is up (0.050s latency).
    Not shown: 999 closed ports
    PORT STATE SERVICE
    6000/tcp open X11

    But my connections are refused with any app I try. I’m trying this over wifi on the same non-routeable network.

  53. a3nm says:

    Something that would be funny to do with the X Server is to use x2x to run X applications on the device (run from a chrooted debian, for instance) and control them using a computer’s mouse and keyboard. The only problem with this is that android-xserver does not support the XTEST extension. Do you have any plans to implement it?

    Another thing: when trying to run the “bb” program from a chrooted Debian (package “bb”), android-xserver crashes in an ugly way.

    In any case, thanks a lot for developing this!

    • mattkwan says:

      I don’t have any plans to add extensions in the near future, but I’m happy to fix bugs. When the server crashes, what exactly happens? Can you reproduce the problem by running the program on a remote machine?

      • a3nm says:

        The problem is not with the bb: I can run bb on the device and send its output to an Xnest server on my computer, and it works.

        If I try to run it in android-xserver, I get the following:
        root@localhost:~# DISPLAY=127.0.0.1:0 /usr/games/bb
        XIO: fatal IO error 2 (No such file or directory) on X server “127.0.0.1:0.0”
        after 283 requests (22 known processed) with 0 events remaining.
        android-xserver crashes (“Unfortunately, X Server has stopped”).

        Here is what seems to be the relevant part of the Android log:
        http://paste.fulltxt.net/jG

        Here is the log of strace -E DISPLAY=127.0.0.1:0 bb
        http://paste.fulltxt.net/Pc

        If you want to reproduce the problem yourself, you can install a Debian chroot with “Lil’ Debi” from F-Droid, apt-get install bb, and run bb. If you would like me to run anything to get more info, don’t hesitate to ask.

        Thanks for your efforts!

      • mattkwan says:

        OK, I’ve fixed the bug triggered by bb. The problem was an array overflow in GetImage.
        It should work (or at least not crash) in version 1.11, just released.

      • a3nm says:

        OK, I confirm that it does not crash anymore on 1.11. Thanks for fixing this!

        This being said, there is still a problem with “bb”: it expects keyboard input, but using the keyboard included with android-xserver does not do anything. (Providing the input in the terminal where bb was spawned does not help either.) Here is what I get by stracing bb:
        ; nothing happens when I press keys on android-xserver’s keyboard. I checked that keyboard input works fine with Xnest. I can provide info if you are interested in finding where this bug comes from. [However, I don’t have a genuine need to run bb, so I’m perfectly fine if you don’t care :-).]

  54. An implementation of the XLib in Java could be: http://sourceforge.net/projects/escher/
    A window manager could be: http://sourceforge.net/projects/jdx/

    Maybe it would be worthwile to look into these? And perhaps ship the XLib and/or JDX with the server?

    Nice work!

    • mattkwan says:

      I don’t really have time to add to the X server these days, so someone else will have to do it. Escher looks like a good starting point, and I think the original version of twm just used Xlib, so that might a target for porting. But running ldd on the latest version of twm shows dependencies on libXext, libXmu, libXt, etc.

      However it’s done, it will need to be a separate download. The choice of window manager – if any – should left to the user.

  55. Jay says:

    I would pay for this

  56. Rogerio Villafranca says:

    Hi.

    I have installed your software from Google Play but when I try to open an application from the client it returns an error message like that:

    XIO: fatal IO error 12 (Não foi possível alocar memória) on X server “192.168.1.100:0”
    after 87 requests (87 known processed) with 3 events remaining.

    (Well, the portuguese parenthesised phrase means “Cannot allocate memory”.)

    I got that specifically from xterm, but other apps give similar answers, just changing the number of requests and events remaining.

    Any clue of what can be happening?

    Thank you very much for your attention and congratulations for the great (I guess 😉 ) software you have made.

    • mattkwan says:

      Hmm, that’s strange. If the client is running out of memory, that means malloc is failing. And modern PCs have so much RAM + swap space, that should never happen. If you run the “free” command, how much free memory does it show?

      The simplest, most lightweight X program is xlogo. As an experiment, see if that works.

      • ArtifTh says:

        I also experience same problem with xterm application. Xlogo and xclock works fine, but xeyes simply crashes the Xserver. Also, i tried to launch Emacs-lucid, but it prints “Connection lost to X server `:0′” and dies.

      • mattkwan says:

        What Android device are you running the application on? And what version of Android is it running?
        And just to confirm, when you run Emacs-lucid it’s the server that crashes?

      • ArtifTh says:

        I’m running the application on Wexler T7008B (probably it’s branded chineese one) with Android 4.0.4. And no, when I run emacs X server continue work, emacs dies.

      • mattkwan says:

        I don’t know why emacs dies, but I think I’ve discovered why xeyes causes a server crash.

        In Android 3.0 they introduced hardware acceleration for view rendering, but doesn’t support all the canvas graphics operations. In particular, Canvas,clipRegion causes an UnsupportedOperationException. This is a massive pain in the arse, because the Android 2.x API has no way to detect or disable hardware acceleration. Yet again Android breaks backward compatibility.

        I can probably work around the problem by catching the UnsupportedOperationException and setting a flag that bypasses all future clipRegion commands. Shaped windows will stop working, but at least hardware acceleration will keep things running fast.

        However, I don’t have a tablet, so I have no way of testing the changes. Would it be possible to send you APK files for testing?

      • ArtifTh says:

        Yes, you can send me APK by email: artifth@artifth.ru.

  57. Anon says:

    Hi.. Great Project, mi question is ¿How do I get get screens from OS windows?

    • mattkwan says:

      You can do screen grabs through the Android debugger. There may be other options – I’d suggest Googling “Android screenshot” or similar.

      • Anon says:

        Sorry for my bad Question, really; I want is to run an application remotely Windows (Operating System) and see it with this X server (or if possible from linux)

  58. Paul M says:

    I couldn’t get a window manager to run without crashing (from chroot’ed debian linux)… tried fvwm, openbox and fluxbox.

    I could get xterm up (xterm -ls -C /bin/bash)

    firefox ran but didn’t fill the screen. is a bit slow 😉

    my HTC doubleshot’s touchpad and its button don’t seem to do much.. the keyboard somewhat works but hitting return when entering a

  59. SidGabriel says:

    I have to congratulate you on this thread, and give December it’s proper turn with the rest of the months. You’ve had a steady flow of comments on this since March! There is a lot of value in X11 and a ton of interest in what happens next. I was sad to see that Macs are no longer shipping with X11. Apparently the company forgot what was NeXt. I’m sure you know, Tim Berners Lee wrote the World Wide Web 1.0 application in interface builder on X on a NeXt workstation at CERN. I’m almost as happy to see this as I was to see The UrQuan Masters find eternal life after SC2 in open source. If you wanted to get a window manager running in Android, which one would you do? Enlightenment seems like a good move because Metacity, KDE, Gnome all seem so big. Blackbox is too minimal to be poking at on a touch screen. Any other contenders? What did the Zaurus run? And just one more thing: what is the significant hurdle in getting XLIB running natively in android? Would people be more interested in pursuing it if they knew it would start a sweet new super powered operating system? Isn’t the main task to port from C to the Android NDK(Java)?

    • mattkwan says:

      Yep, the main hurdle is porting Xlib (and Xaw, Xt, X*) to Android. I reckon porting them cleanly to Java would take tens of man-years. Tweaking the C code to work with the Java Native Interface might be faster, but you’re still dealing with tens of thousands of line code.

    • Paul M says:

      the stock ROM on the zaurus ran qtopia, a “desktop” written in quite an old version of QT which was never released as a non-commercial version but there were sufficiently close OSS versions of QT you could develop with.
      there were other ROMs which were qt2.3.x, GPE, Opie or X11/Enlightenment

      one of the best alternatives was Angstrom: http://www.angstrom-distribution.org/

  60. Today I have been playing around with android xserver and I have accomplished more than I have before. The trick was to use a program called gexec. So I have an android tablet and on the run I debian-kit where I have a debian console running in connectbot and then Xserver. The problem has been that I have not been able to start any xterm on the xserver. Today I suddenly remembered a small command-program-starter that I once saw. It’s called gexec. I installed the program on my debian system

    apt-get install gexec

    Than I started the xserver and than I went back to connectbot/debian and did

    export DISPLAY = 127.0.0.1:0.0; gexec

    And that actually gave me something usable. I went back to the Xserver and here I had a small command-line-dialog-box. From there I typed xterm (which I had previously installed) and now started xterm and it worked fine. From here I could also start a workable version of jwm (joe’s window manager) that I had previously installed. So if I build it op step by step on the Xserver beginning from gexec it works much better than when I try to start things from connectbot.. I am quite sure that this setup could be adapted and refined to be usable. I stopped, however, since there are still many things that do not work satisfactorily eg good movie viewing with mplayer too slowly as previously mentioned, but real fun it was 🙂

  61. Magnus says:

    This is awesome! Thanks mattkwan!
    xclock, xterm etc works fine.
    Didn’t manage to display an image though. I tried eog, display, ffplay.
    I get Xlib: extension “RANDR” missing on display “90.131……..:0.0” + other error messages on serveral applications I start.
    Anyone succeeded in displaying a jpg?

  62. Can you make it work on my Google TV?

    • mattkwan says:

      No idea. My guess is that it will either work or it won’t. I doubt that my efforts will make any difference.

    • mattkwan says:

      The Play Store is treating Google TV as an unsupported device, with no way to enable it. It’s possible Google TV doesn’t provide some feature that’s specified in the application’s manifest.

      The X server’s manifest only explicitly requires internet access, but there may be some implied requirements that are incompatible with Google TV.

      • Thanks for the work here. This is an awesome addition to my android devices!

      • Mikael says:

        Yes it is not compatible with Google TV since android.hardware.touchscreen is required by default.

        “If you want your application available to devices that provide a fake touch interface (or even devices that provide only a d-pad controller), you must explicitly declare that a touch screen is not required, by declaring android.hardware.touchscreen with android:required=”false”. You should do so even if your application uses—but does not require—a real touch screen interface.”

        http://developer.android.com/guide/topics/manifest/uses-feature-element.html

  63. jakes says:

    Apologies for this total n00b query, but I’m a little bit snookered here.

    I’ve installed the app from the market onto my unrooted tablet, as well as the requisite conectbot.
    I’ve SSH’d into both the localhost & a remote Debian system.

    I’m a little bit stuck on host to get a (local) CLI terminal on theAndroid device, so that I can start throwing X-over-SSH.

    Can you please provide some documentation or guide on any of the pages on how/where to begin.

    • mattkwan says:

      The X server doesn’t support SSH tunneling, so you won’t have much luck. X applications have to transmit in the clear, usually over port 6000.

      • Rainer says:

        I know, searching is sometimes hard to perform…

        ‘For tunneling via ssh you need something like this:
        “-R 6011:localhost:6000″
        Then “export DISPLAY=:11.0″’
        And
        ‘This will not work, if the target system is behind a firewall.
        Also I would recomand to activate accesscontrol by default and to allow only 127.0.0.1 as standard.
        To get it to work through a firewall open a remote port forward from a port bigger than 6000 and set DISPLAY to :[portnumber-6000] befor starting your xterm.

        Connectbot:
        Remoteforward 6013:127.0.0.1:6000

        Then start the X-server

        After that switch back to connectnot and enter
        DISPLAY=:13.0 xterm’
        Should give enough hints to perform ssh tunneling.
        Btw. no X server knows anything about the ssh protocol, the X tunneling is always done by the ssh client and the ssh server.
        May be this information should find its way to the FAQ.

      • jakes says:

        (got similar info via IRC, thanks)

        Info in FAQ/wiki on getting a simple terminal/ X app post-install would be handy, thanks 🙂

        Learnt a few more tricks today 😀

        tried throwing XDMCP, but didn’t quite work out (yet)

  64. geegee says:

    looks very promesing!

    even firefox sorta starts up.. despite randr messages..

    will try it 2 night with keyboard and mouse..

    just wish i could use wireless mhl hub with rooted phone.. but that’s another story

  65. This is a great effort !

    Can you tell me how exactly to do this?
    I have a ubuntu 10.10 running in Virtualbox inside my win7. I have set up a network between pc, the ubuntu vm and my phone.
    Now I want to try seeing windowed apps inside my android.

    Can you tell me step by step what exactly need to be done?

    thanks a lot

  66. Thanks mattkwan.

    Is it this Xserver works with Xdmx?

    I try to run on PC:
    $ Xdmx :1 -display 192.168.1.137:0

    And the output:
    (II) dmx: Generation: 1
    (II) dmx: DMX version: 1.2.20070424 (DMX Project)
    (II) dmx: DMX Build OS: Linux 2.6.42-34-generic i686 (Ubuntu)
    (II) dmx: DMX Build Compiler: gcc 4.6.3
    (II) dmx: DMX Execution OS: Linux 3.2.0-37-lowlatency #37-Ubuntu SMP PREEMPT Mon Jan 28 13:38:48 UTC 2013
    (II) dmx: DMX Execution Host: alex-Inspiron
    (II) dmx: MAXSCREENS: 16
    (II) dmx: Using configuration from command line
    (II) dmx: Added 192.168.1.137:0 at 0 0
    (II) dmx[o0/192.168.1.137:0]: Name of display: 192.168.1.137:0
    (II) dmx[o0/192.168.1.137:0]: Version number: 11.0
    (II) dmx[o0/192.168.1.137:0]: Vendor string: Open source
    (II) dmx[o0/192.168.1.137:0]: Vendor release: 0
    (II) dmx[o0/192.168.1.137:0]: Dimensions: 1024×720 pixels
    (II) dmx[o0/192.168.1.137:0]: 1 depths on screen 0: 32
    (II) dmx[o0/192.168.1.137:0]: Depth of root window: 32 planes (32)
    (II) dmx[o0/192.168.1.137:0]: Number of colormaps: 1 min, 1 max
    (II) dmx[o0/192.168.1.137:0]: Options: backing-store yes, save-unders no
    (II) dmx[o0/192.168.1.137:0]: Window Manager running: no
    (II) dmx[o0/192.168.1.137:0]: 1024×720+0+0 on 1024×720 at depth=32, bpp=32
    (II) dmx[o0/192.168.1.137:0]: 0x01 TrueColor 32b 8b/rgb 256 0xff0000 0xff00 0x00ff *
    (II) dmx[o0/192.168.1.137:0]: DPMS not supported
    (**) dmx: dmxBECreateColormap: No visual found
    (II) dmx[o0/192.168.1.137:0]: (request) s=1024×720+0+0 r=1024×720+0+0 @0,0 (0) (be=1024×720 depth=32 bpp=32)
    (II) dmx[o0/192.168.1.137:0]: s=1024×720+0+0 r=1024×720+0+0 @0,0 (be=1024×720 depth=32 bpp=32)
    (II) dmx: Using 1024×720 as global bounding box
    (II) dmx: XSync batching with 100 ms interval
    (II) dmx: Shadow framebuffer support disabled

    Fatal server error:
    no screens found

  67. mrabosoma says:

    Hi, an excellent app for Android developers,

    I have tried to run a graphical application tool (qmon) from Open Grid Scheduler software. I can run it using my pc an Xming x server, but with an 4.1.1 Android tablet I have encontered erros. I have also tried to use fvwm, but this window manager also fail to load. The cursor in the tablet changes to a watch that remains forever. No success with twm. The errors shown are:

    administrador@hpcserver:~$ qmon
    XIO: fatal IO error 11 (Resource temporarily unavailable) on X server “172.25.80.180:0.0”
    after 76 requests (76 known processed) with 0 events remaining.
    administrador@hpcserver:~$

    when fvwm starts, some warnings relative to fonts are shown.

    Any idea would be apreciated.

    Thanks in advanced,

  68. kiran says:

    i tried x server on my android phone but it failed to display the GUI Applicaion like any jar from the server .and also not able to perform any CLICK event on any GUI app.i.e button click is disable, it only shows mouse cursor with arrow.

  69. Michael Enke says:

    Hi, it’s an excellent work, thanks a lot!
    I’ve found a few small problems:
    1: Only from code review, no real case scenario:
    Client.java -> doComms(): If it’s a “big/extended request”,
    bytesRemaining (arg3 for processRequest) must be calculated: requestLength * 4 – 8
    The requestLength * 4 – 4 is valid only for normal request
    2: Viewing an image with “display “, the XServer freezes until Crtl+C for “display”,
    no graphics output:
    Client.java -> processRequest(…): in “case RequestCode.CreatePixmap”:
    remove the 2 “_inputOutput.readSkip (bytesRemaining);”, all bytes are already read
    with 2x readInt() and 2x readShort()
    3: If an image contains transparency, the client aborts with:
    internal X error: BadLength (poly request too large or internal Xlib length error) …
    This is due to wrong expectation of shape mask data length (format == 2 && depth == 1),
    modified Drawable.java -> processPutImage(…) (where should I send the patch?)
    and added InputOutput.java -> readBitsShapeMask(…)

    And I need a new feature, to make the X server touch-aware,
    to translate a screen touch into left mouse button press:
    ScreenView.java -> onTouchEvent(…):
    added behind the “synchronized {…}” and before “return true”:

    // > 0.4: Have a threshold to be able for lower values to use the volume key
    if(event.getAction() == event.ACTION_DOWN && event.getPressure() > 0.4) {
    // 1 is the left mouse button
    updatePointerButtons (1, true);
    } else if(event.getAction() == event.ACTION_UP) {
    updatePointerButtons (1, false);
    }

    Maybe the 0.4 (=40%) can be put into a configuration,
    setting it to e.g. 150% always disables it.
    Again, thank you for your 20%

  70. Chan Kar Heng says:

    Would it be possible to have a version that uses Android’s window manager as the window manager in X? similar to Cygwin X’s -multiwindow option.
    http://x.cygwin.com/docs/man1/XWin.1.html
    Or Wayland would be good too. 🙂

    • mattkwan says:

      An X window manager has to use the X protocol to interact with the user, and the Android window manager doesn’t use X.
      With Wayland, I could be wrong, but I don’t think it works across a network.

      • Chan Kar Heng says:

        “An X window manager has to use the X protocol to interact with the user, and the Android window manager doesn’t use X.” – Yes I’m aware 🙂 If you look at generally how Cygwin has implemented Cygwin X’s -multiwindow option, it’s the same thing. Windows doesn’t use X. Yet, folks at Cygwin managed to make a bridge/interface, so that X applications mostly work under Windows’s GUI window manager. X apps would appear under Window’s task manager, & one could Alt-Tab between those X apps & Windows apps as if they were all Windows apps. You might need to install them & get them working to really understand what I mean.
        Anyway, Jolla Sailfish OS seems to be coming up with something of the same since a while ago. Jolla Sailfish, while it will be mostly very *n*x’ish environment, promises to be able to run Android apps.

        Anyway, whatever I mentioned, I anticipate it to be a gargantuan task. 🙂

  71. David says:

    Hi! I tryed that app yesterday on my Samsung Galaxy Tab 2 but I don’t understand how to work:
    1 I start Android Xserver on my table
    2 I connect to my Ubuntu-box through SSH
    3 On my tablet I write: env DISPLAY=192.168.0.103:0 xclock (192,168.0.103 is IP of my tablet)
    But I don’t see anything -> where is my error?
    Thanks! 🙂

  72. Daveysaxt says:

    Hii just wondering if the server supports xdmcp (is using the query option to log into the remote machine via xdm ?

  73. Jin-oh Kang says:

    I think you should implement the server in the NDK or compile as arm-none-linux-gnueabi.
    It would be even faster and easier to port the X Server.

  74. Jin-oh Kang says:

    By the way, why aren’t you doing anything with Google Project Issues? In the issue tracker, 32 issues are all marked as New.

    • mattkwan says:

      Until recently I wasn’t getting e-mail notifications, so I didn’t realize the issues existed. A few of them have been fixed in the latest update, and I’ll clean up the issues in a few weeks when I have some spare time.

      • euna8815 says:

        Thank you for it. However, you can, at least apply patch files from issue tickets now…
        If you have more spare time than you can port x server using NDK simply.

      • mattkwan says:

        In the latest release (Sunday) I applied all the patches relating to bugs.

  75. Michael Enke says:

    I want the XServer not to die when I close the Activity. Therefore I added into XServerActivity.java:

    @Override public void onBackPressed () {
    moveTaskToBack(true);
    }

    To have to possibility to stop the XServer with a long key press on back:

    @Override public boolean onKeyLongPress (int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK) {
    finish();
    return true;
    }
    return super.onKeyLongPress(keyCode, event);
    }

    Is this the right way? AFAIK a Service can not be used for graphics output.

    Next interesting detail would be to start the XServer after boot automatically.
    How to do this is widely described in the web, but I found 2 oddities I can not solve:
    1: After boot the XServerActivity is brought to the top.
    How can I avoid it is showing on top?
    How can I call something like moveTaskToBack() from the
    BroadcastReceiver which calls context.startActivity(intend)?
    2: The so called XServerActivity, when brought to the back with a short back key press:
    If I click on XServer icon, it calls onCreate method again,
    causing another XServer screen to show above the original.
    How comes that behaviour of activity started with startActivity()
    is different then activity started from home screen?

  76. Michael Enke says:

    typo in Font.java:

    for (float width: widths) {
    if (width minw) minw = width;
    }

    In the second line must be 2x maxw!
    Not sure what this is causing …

  77. I found a trap for remote port forwarding. That is “Don’t keep activities” option in “Developer options” settings. If I have enabled this option, any X applications cause an error such as “Can’t open display :13.0”. I must disable this option for X Server.

    My tablet is ASUS MeMO Pad HD7 whose Android is 4.2.2. I am using VX ConnectBot instead of ConnectBot.

  78. cspert says:

    In case you are interested, I ported libx11 to Android NDK, together with the xclock sample as proof-of-concept. Works fine with your xserver 🙂

    http://code.google.com/p/libx11-android/

  79. Curt says:

    It took me a little while to figure this out, but I finally got xserver working together with connectbot. I set up the port forward on connectbot and I was using remote port 6015 to localhost:6000, the way like everyone else. On the remote Debian Linux box I was SSH’ing to, typing :

    $ export DISPLAY=:15

    was NOT enough for me. I had to type:

    $ export DISPLAY=localhost:15

    Otherwise I got the usual “Error: Can’t open display: :15”

    Thank you mattkwan for your hard work! This is neat piece of software you have shared.

  80. Hamilton says:

    Impressive to see this as a working codebase and not just a thought on paper somewhere, very nice job!

  81. Groeg3 says:

    Is there any chance for this app to be made backwards compatible with Android 2.1 (or a one-off version)? I’m running a rooted Nook Simple Touch ereader which is stuck on Android 2.1 and would love to try running Linux via an xserver on it.

  82. Paul M says:

    Maybe restarting but with Wayland instead would be interesting?

  83. Johan P says:

    Unfortunately java just dumps when the X target is this android-x-server.
    Did get my java app to show on XServer XSDL though.

  84. Is this project still active?
    If yes, I have a question. Many applications are hardly usable without Ctrl or function keys. But the keyboard I can activate in your X server app does not exhibit these. Do I miss some special trick or do I have to install a special keyboard app? Or what else?

    • mattkwan says:

      The project isn’t under active development, but I still put out the occasional bug fix.

      The app just uses the default Android keyboard, which doesn’t appear to have CTRL keys. I don’t know if a new keyboard would fix this – I’ve never investigated. Also I’m not sure if the CTRL key would be correctly processed by the current app, although it would be fairly easy to fix.

      • Dear Matthew, in this case I answer wth two feature requests that were inspired by the app “VX ConnectBot”, an SSH client for Android. I would be happy if you could implement at least the first of both. The first should be rather easy to implement, the second is probably complicated.

        1) Instead of being a mouse substitute, the volume keys could also be a keyboard substitute. What about making the volume keys a Ctrl and Esc prefix? When I press “volume down” followed by the letter “i”, I would like the X server to send Ctrl-I, i. e. a tabulator key. When I press “volume up”, the X server will send Esc, which I could use to enter the escape sequences of cursor or function keys in a terminal window. Of course, it must be possible to quickly switch the volume keys from mouse operation to key operation and back.

        2) What about one or more popup windows with buttons that provide the missing keys like Home, End, F1, Cursor and Ctrl codes?

  85. Daniel G. says:

    Hi,

    i forked the project and pushed it to Android SDK 23

    https://github.com/nwrkbiz/android-xserver

  86. […] perhaps it’s a bit tricky to connect to it through X forwarding via SSH… you must figure it […]


Leave a reply to Groeg3 Cancel reply