GTK recognizes a cursor with a broken name with Wacom FAVO ET-0405-U

I have a Wacom FAVO tablet ET-0405-U which is very old. The driver from Wacom (V605-7Jwi.exe) doesn’t support Windows 7/8 but the driver for Vista works well.

With compiled GTK+ 2.14.12, GIMP 2.8.2 on Windows 7 can recognize the tablet, however, if you look at the GIMP 2.8.2 input devices editor, you’ll notice there’s a cursor with a broken name.

The cursor name is retrieved through WinTab API in gdk/win32/gdkinput-win32.c in GTK+. The comment says

/* Wacom tablets seem to report cursors corresponding to
 * nonexistent pens or pucks. At least my ArtPad II reports
 * six cursors: a puck, pressure stylus and eraser stylus,
 * and then the same three again. I only have a
 * pressure-sensitive pen. The puck instances, and the
 * second instances of the styluses report physid zero. So
 * at least for Wacom, skip cursors with physid zero.
 */
(*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PHYSID, &physid);
if (wcscmp (devname, L"WACOM Tablet") == 0 && physid == 0)
  continue;

I made a simple program to use WTInfo() to get tablet information (source code). The result for my tablet is somewhat aligned with the comment in GTK+ (output). WinTab reports six cursors but only two of them are valid.

  • Pressure Stylus
  • Eraser

However, when GTK+ tries to get the value for CSR_PHYSID, WTInfo() returns 0, without writing to physid which is uninitialized. As GTK+ doesn’t check the return value from the function, it recognizes cursors which doesn’t actually exist.

I modified the code as below

if ((*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PHYSID, &physid) == 0)
      physid = 0;

This removes the cursor with broken name.

Building GTK+ 2.14.12 for GIMP 2.8.2 for Windows

There’s a lot of blog articles about building GTK+ and related libraries for Windows with MinGW. Building them on Windows is not a straight forward task. Most write about the trick and workaround, but those workaround is case by case and requires a lot of searching on the web. So I’ve decided to write one for me.

Precompiled GTK+ for Windows

The GTK+ projects provides the precompiled packages for Windows. GTK+ version is 2.24.10 as of Sep 23, 2012. According to this page, GIMP 2.8.2 requires GLib 2.30.2, however, the precompiled GLib is 2.28.8.

Preparing environments

We are building GTK+ on /opt/gimp. Let’s prepare some environment variables first. I wrote a small shell script env.sh to do this. Type . env.sh before building.

export GIMP_ROOT=/opt/gimp
if [ -z "$PATH_OLD" ] ; then
	PATH_OLD=$PATH
fi
if [ -z "$PS1_OLD" ] ; then
	PS1_OLD=$PS1
fi
export PATH=/opt/gimp/bin:/c/Python27:$PATH_OLD
export LANG=C
export PKG_CONFIG_PATH=$GIMP_ROOT/lib/pkgconfig
export CPPFLAGS="-I$GIMP_ROOT/include"
export CFLAGS="-O2 -g -march=i586 -mms-bitfields -I$GIMP_ROOT/include"
export CXXFLAGS="-O2 -g -march=i586 -mms-bitfields -I$GIMP_ROOT/include"
export LIBS="-L$GIMP_ROOT/lib"
export PS1="gimp$ "

What to build first?

There’s a lot of dependency among the packages. What to build first? Many configure scripts of libraries use pkg-config. However, building pkg-config requires Glib to build. (–with-internal-glib probably works but I didn’t notice when building this.) Zlib is required by GIO of Glib and libffi is required by GObject of Glib. These two do not depend on other packages. So we should start with them.

Zlib 1.2.7

Zlib (http://zlib.net/zlib-1.2.7.tar.gz) doesn’t use pkg-config. It has makefiles for Windows. You need to use SHARED_MODE=1 to install the shared library zlib1.dll.

make -fwin32/Makefile.gcc -j4
INCLUDE_PATH=$GIMP_ROOT/include \
LIBRARY_PATH=$GIMP_ROOT/lib \
BINARY_PATH=$GIMP_ROOT/bin \
make install -fwin32/Makefile.gcc SHARED_MODE=1

libffi 3.0.11

libffi (ftp://sourceware.org/pub/libffi/libffi-3.0.11.tar.gz) is a portable foreign function interface library. It is used by GObject to implement marshalling. Building libffi is straight forward.

./configure --prefix=$GIMP_ROOT
make -j4
make install

GLib 2.33.14

The configure script of GLib uses pkgconfig to locate Zlib and libffi. We need to specify manually to avoid it. See Re: circular dependency between glib and pkg-config

There’s a build break in GLib 2.3.14. Apply the patch [glib] gio: Fix build on Windows.

ZLIB_CFLAGS=-I$GIMP_ROOT/include \
ZLIB_LIBS="-L$GIMP_ROOT/lib -lz" \
LIBFFI_CFLAGS=-I$GIMP_ROOT/lib/libffi-3.0.11/include \
LIBFFI_LIBS="-L$GIMP_ROOT/lib -lffi" \
./configure --prefix=$GIMP_ROOT
make -j4
make install

pkg-config 0.27

Pkg-config now can be built.

./configure --prefix=$GIMP_ROOT
make -j4
make install

ATK 2.5.91

Building ATK 2.5.91 is straight forward.

./configure --prefix=$GIMP_ROOT
make -j4
make install

libpng 1.5.12

GDK-Pixbuf uses libpng (http://downloads.sourceforge.net/project/libpng/libpng15/1.5.12/libpng-1.5.12.tar.xz).

./configure --prefix=$GIMP_ROOT
make -j4
make install

GDK-Pixbuf 2.26.4

http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/2.26/gdk-pixbuf-2.26.4.tar.xz

./configure --prefix=$GIMP_ROOT
make -j4
make install

FreeType 2.4.10

Cairo uses FreeType for one of font supports (http://download.savannah.gnu.org/releases/freetype/freetype-2.4.10.tar.gz).

./configure --prefix=$GIMP_ROOT
make -j4
make install

expat 2.1.0

Fontconfig uses expat to parse its configuration files (http://downloads.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz).

./configure --prefix=$GIMP_ROOT
make -j4
make install

Fontconfig 2.10.1

Cairo and Pango use fontconfig (http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.10.1.tar.bz2).

./configure --prefix=$GIMP_ROOT
make -j4
make install

Pixman 0.26.2

Cairo uses Pixman. Pixman (http://cairographics.org/releases/pixman-0.26.2.tar.gz) is distributed with cairo.

./configure --prefix=$GIMP_ROOT
make -j4
make install

Cairo 1.12.2

Pango uses Cairo (http://cairographics.org/releases/cairo-1.12.2.tar.xz).
There’s a build break in util/cairo-missing/cairo-missing.h (https://github.com/libgit2/libgit2/issues/542).
I added this around line 44.

#define _SSIZE_T_DEFINED

Rest of the process is straight forward.

./configure --prefix=$GIMP_ROOT
make -j4
make install

HarfBuzz 0.9.4

HarfBuzz (http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-0.9.4.tar.bz2) is a OpenType shaping library. Recent Pango requires HarfBuzz to enable the Cairo rendering support.

./configure --prefix=$GIMP_ROOT
make -j4
make install

Pango 1.31.2

GIMP requires Pango’s Cairo rendering support (http://ftp.gnome.org/pub/gnome/sources/pango/1.31/pango-1.31.2.tar.xz). Make sure that FT2, Win32 and Cairo is supported after configured.

./configure --prefix=$GIMP_ROOT
make -j4
make install

GTK+ 2.24.12

Finally GTK+ (http://ftp.gnome.org/pub/gnome/sources/gtk+/2.24/gtk+-2.24.12.tar.xz). All requisits are ready now.

./configure --prefix=$GIMP_ROOT
make -j4

Building fails while generating gtkbuiltincache.h. Type with admin rights (MinGW/MSYS development environment
Part 3: Building GTK+
).

cd gtk
make gtkbuiltincache.h

Then continue

make -j4
make install

Run Demo

GTK+ includes demo program. Type

gtk-demo

to see if every thing is okay.