Using XInput2 with Xlib on N9

Mon, 22 Sep 2025 12:00:00 +0000

Example code for how to handle multi-touch events using nothing but Xlib (and the XInput2 extension) on a N9, no SDL involved. Including EGL, OpenGL ES and X11 shared pixmap access.

While the SDL1.2 port on MeeGo 1.2 Harmattan has support for multi-touch events (via patches), using SDL 1.2 is not as "fun" (for certain values of fun) than using it directly via Xlib. The SDL1.2 patch helps to get a good idea of how it's done, so it can be used as a starting point.

Apart from learning about X11 and implementations of its protocol extensions, one can use this to build a dynamically linked binary for the N9 that doesn't need any third party libraries - just libraries that are already included in the default firmware image (so no need to set up n9repomirror, etc...).

Compared to contemporary multi-touch on X11 using XInput 2.2 (the version which adds multi-touch support to the protocol), the N9 ships (at least in the latest software update) with X.org 1.9.5 and XInput 2.0.

More details on the X11 capabilities of the N9 are available in the Nokia N9's xdpyinfo -ext all output.

In addition to exploring XInput2, this example also uses EGL (the N9 has a PVR SGX530 GPU, and proprietary graphics drivers). EGL 1.4 is shipped on the device, and the following values are returned by eglQueryString():

EGL_CLIENT_APIS = 'OpenGL_ES OpenVG '
EGL_VENDOR = 'Imagination Technologies'
EGL_VERSION = '1.4 build 1.4.14.2514 Nokia'
EGL_EXTENSIONS = 'EGL_KHR_image EGL_KHR_image_base EGL_KHR_image_pixmap EGL_NOK_image_shared EGL_KHR_gl_texture_2D_image EGL_KHR_gl_texture_cubemap_image EGL_KHR_gl_renderbuffer_image EGL_KHR_vg_parent_image EGL_NOKIA_texture_from_pixmap EGL_NOK_texture_from_pixmap EGL_KHR_fence_sync EGL_IMG_context_priority EGL_KHR_lock_surface EGL_KHR_lock_surface2 EGL_NOK_image_yuv EGL_NOK_image_yuv_pixmap EGL_NOK_image_yuv_framebuffer EGL_NOK_image_framebuffer '

The example also brings up an OpenGL ES 1.1 context and uses that to visualize the multi-touch touch points (when touched).

Plus, it also implements the _NET_WM_PING protocol to test the N9's "application is not responding" UI (#define FREEZE_FRAME_ONCE in x11egl.c).

And finally, if you add #define RENDER_STATUSBAR to x11egl.c, it grabs the X11 pixmap handle for the status bar from D-Bus (via com.nokia.systemui, path /statusbar, interface com.meego.core.MStatusBar and method sharedPixmapHandle -- implemented using popen("qdbus ... due to lazyness on my part). The X11 pixmap is then retrieved via Xlib and rendered on the screen using OpenGL ES. Might also come in handy as code example at some point.

Example source code and binary: n9-multitouch.tgz

See also (some additional links for reference):

N9 SDL 1.2 sources and binaries (mirror)

XInput2 extension specification

Linux Kernel Multi-Touch Protocol

xf86-input-multitouch

xorg-input-mtev