How to get Pen events for Wacom Tablets

My most recent project has been putting together the pieces for an art application combining 3D with 2D in a way that should make it easier to quickly assemble scenes in a more natural 2D way than currently any program I’ve found offers. 2D software apps usually have horrible handling for 3D controls, and 3D specialty apps usually don’t have nice 2D art features. So that’s where my app comes in.

The problem you eventually run into when designing a nice 2D program is trying to figure out how to get the UI events for a drawing tablet pen. Qt has tablet pen events already handled nicely, and example is given in the documentation for Qt 6.4,2, so you shouldn’t have to dig through the codebase of an art application like Krita. I might add that Qt is also a better choice of GUI for art apps because it can handle high-definition screens better. But I’m cheap and my OS’s GUI is GTK3, so to start with, I figured I’d build my app’s front end with gtkmm and make the backend agnostic so I could swap out gtkmm for Qt later on if I decided that was the best option.

Cutting to the case, how do we get the input for a tablet pen? The most direct way is using XEvent for Linux, but it is also possible to do from GTK so you don’t have to manually handle XEvents (which would be ugly and not cross-platform). Thankfully, Wacom – the specialists who know how their devices work – has put together example code for you that this beloved author spent many hours scouring the internet for.

The Wacom code for Linux can be found on Github here.

The GTK examples are here. The GTK events will be cross-platform.

However, before you run into the snag I did, I have to inform you that the makefile included in the GTK sample is slightly wrong. In it you will see the line:

$(CC) $(LDFLAGS) $(GTK_LIBS) $^ -o $@

This incorrectly puts the object files after the libraries, which causes a ton of undefined reference errors when the linker kicks in. The explanation is here:

” It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded. “

The correcting is to put the “$^ -o $@ ” part before $(LDFLAGS) and all the errors disappear. In your make files, always remember to put the pkg-config stuff (for GTK or anything else) after the object files.

Hopefully my article saves you from many hours of hopeless searches for “how to get pen input”.

If you want to see Pen events in a real program, you’ll have to scour the GIMP codebase. XournalApp also gets pen input, but when I checked the codebase, I found they estimate pen pressure by speed rather than getting it directly.

Proposal: GRASS: GRAphics Sharing Server

This is an idea I am very interested in implemented as free software, but I’d like some feedback and some help from people who actually are involved in creating the graphics applications I have in mind, such as Krita, the GIMP, Inkscape, and Blender.

The Problem

Many 2D art programs lack 3D modeling features that would be useful in creating artistic works. Likewise, many 3D modeling programs lack complex 2D art editing features that would be beneficial in modeling (like texture design). Currently, exchange of data requires the tedious saving and opening of files. And you have to hope that both applications can open the same file formats. For improving the creative process, it would be beneficial if the features of both applications could be available in real time.

Idea

The solution is NOT creating a new program that integrates the features of both types of applications. That’s creating yet another standard and duplicating work others have already done. Instead, we want to harness the power each existing program already has and synchronize their data, that is, by allowing them to exchange data in real time. We want the data linked so that users can immediately see the results.

Continue reading

Predictions: Pads for the Tactile

Imagine this: You’re on your mobile device having a video call with family a long ways away. Your sibling raises the family pet up to the screen. With the flip of a setting, you turn on “Tactile Mode” for your device and proceed to wave your hand over the screen of the device. Small electrical signals come up from the screen and tingle your hand like the fur of your pet on the other end of the net.

Continue reading