📜 ⬆️ ⬇️

Connecting a Wacom Pro pen tablet to Linux or how bash helps artists


If you are a happy owner of Intuos Pro and a proud Linux user, you may have suffered the same failure as me. The fact is that at the time of this writing, there was no normal support for the latest Wacom tablet PCs . However, thanks to the Linux Wacom project and several bash scripts, this problem can be solved.

The whole story began with the fact that I needed to draw a lot for my home project, and the old Genius tablet didn’t fit for that at all. And it was bought by Wacom Intuos Pro Midlle . On a computer with Win7, it was very easy to install and configure. I was particularly pleased with the ability to customize profiles to assign different functions to the keys on the device, depending on the application used. Joy knew no bounds.

Along with this, I realized that buying Photoshop for a project that does not generate income is not at all interesting. The work of developers, however, as well as my freedom, I appreciate and therefore I do not use anything pirated. The gaze was towards free software.

Climbing the sites and forums and disliking the Gimp , I stopped at the program Krita - a very convenient raster editor, with rich settings for brushes. In order to immediately avoid holivar, I will say that Krita is not a replacement for Photoshop, but in terms of drawing it is sometimes more advanced.
')

What is unlucky


By this time, I had to completely transfer to the computer with Ubuntu. Remembering that I had always seen the Wacom section in the settings, I boldly connected the tablet wire. And nothing ... Then I connected the wireless adapter. No result. Search and all sorts of tips - all the same. At one time, I conjured with the settings of Genius and thought that there was a conflict somewhere. Long wanted to try Mint and Cinnamon , I downloaded and fixed it. Nothing again.

The Linux Wacom Tablet Project came to the rescue, one of the main authors of which is Red Hat employee Peter Hatterer. Not to say that everything was smooth from the first, but this sequence of actions with askubuntu helped me:
  1. Download the latest version of the input-wacom kernel driver from here:
    http://sourceforge.net/projects/linuxwacom/files/latest/download
  2. If necessary, install the dependencies:
    sudo apt-get install build-essential libX11-dev libxi-dev x11proto-input-dev xserver-xorg-dev libxrandr-dev libncurses5-dev autoconf libtool
    sudo apt-get install linux-headers-generic
  3. Unpacking
    tar xjvf input-wacom-0.20.0.tar.bz2
  4. Turn inside
    cd input-wacom-0.20.0

    ./configure --prefix=/usr
  5. We put the drivers from the folder under our kernel (I have 3.7)
    sudo cp ./3.7/wacom.ko /lib/modules/`uname -r`/kernel/drivers/input/tablet/wacom.ko

    sudo depmod -a

Depending on whether the tablet was connected, a reboot may be required.

Minutes of happiness


I was happy again, until I realized that only 2 buttons work, and the touch does not turn off when drawing with the stylus. Under KDE and Gnome, there were GUIs , and under my Cinnamon, I had to use the console utility xsetwacom, which later gave a more flexible configuration, and in conjunction with bash, additional features.

The project site has examples of scripts with xsetwacom, but they are not designed for the version of Intuos Pro. I had to experimentally determine the number of buttons (they are somewhat randomly scattered). Plus, in the device list, the tablet is determined differently when connected with a wire \ without a wire.

Pretty advanced setup


I'm not a programmer, but I hoped that I could figure out the scripting language. With output from xsetwacom and grep , the desired device is always substituted into the variable, and notify-send outputs the profile used.
Sample script for Krita
 # ,   ,       DEVICE_STYLUS=`xsetwacom list dev | grep -E -o ".*stylus"` DEVICE_ERASER=`xsetwacom list dev | grep -E -o ".*eraser"` DEVICE_CURSOR=`xsetwacom list dev | grep -E -o ".*cursor"` DEVICE_PAD=`xsetwacom list dev | grep -E -o ".*pad"` DEVICE_TOUCH=`xsetwacom list dev | grep -E -o ".*touch"` #    . notify-send "Using Krita profile" #    #     2    1: MapToOutput 3286x1080+0+0 xsetwacom set "$DEVICE_STYLUS" MapToOutput 1920x1080+0+0 ##    xsetwacom set "$DEVICE_STYLUS" RawSample "2" # -      xsetwacom set "$DEVICE_STYLUS" Threshold "27" #    xsetwacom set "$DEVICE_STYLUS" PressureCurve "5 10 90 95" #    xsetwacom set "$DEVICE_STYLUS" TabletPCButton "off" #       xsetwacom set "$DEVICE_STYLUS" Mode "Absolute" #        xsetwacom set "$DEVICE_STYLUS" Button 1 "1" #   xsetwacom set "$DEVICE_STYLUS" Button 2 "3" #   xsetwacom set "$DEVICE_STYLUS" Button 3 "2" #   ##  xsetwacom set "$DEVICE_ERASER" RawSample "2" xsetwacom set "$DEVICE_ERASER" Threshold "27" xsetwacom set "$DEVICE_ERASER" PressureCurve "0 10 90 100" xsetwacom set "$DEVICE_ERASER" Mode "Absolute" xsetwacom set "$DEVICE_ERASER" Button 1 "1" ##   xsetwacom set "$DEVICE_PAD" Button 2 "key shift" xsetwacom set "$DEVICE_PAD" Button 3 "key ctrl" xsetwacom set "$DEVICE_PAD" Button 8 "key ctrl Z" xsetwacom set "$DEVICE_PAD" Button 9 "key ctrl shift A" # ,     #xsetwacom set "$DEVICE_PAD" Button 4 "key D" #xsetwacom set "$DEVICE_PAD" Button 5 "key E" xsetwacom set "$DEVICE_PAD" AbsWheelDown "5" #    xsetwacom set "$DEVICE_PAD" Button 1 "key E" #    xsetwacom set "$DEVICE_PAD" AbsWheelUp "4" #    xsetwacom set "$DEVICE_PAD" Button 10 "key ctrl K" xsetwacom set "$DEVICE_PAD" Button 11 "key ctrl M" xsetwacom set "$DEVICE_PAD" Button 12 "key O" xsetwacom set "$DEVICE_PAD" Button 13 "key I" xsetwacom set "$DEVICE_PAD" ScrollDistance "10" xsetwacom set "$DEVICE_PAD" TapTime "50" 


In principle, it is clear from the comments what each parameter is responsible for. Notice how the physical keys are associated with their numbers within the program.
Connection


The next disappointment was that there were no profiles for various programs. In principle, you can make several scripts and configure hot keys to activate each. However, with frequent switching between applications, it begins to cause some inconvenience.

Bash to help


I understand that the implementation below is still that bike, but in practice it does its job well, without loading the system.
And so, we will need:
  • awk - to find the window ID in the output. It was possible to do with a cut or grep, but after reading the discussion, I decided to implement it on awk
  • xprop - used to get the current window in focus
  • wmctrl - to get a list of IDs of windows that have the desired keyword, for example, Firefox - to reassign keys when switching to a browser. There are also cases when several windows are running, for example, with the name Terminal, they have different IDs, and the profile should be the same

Script to switch profiles
 #!/bin/bash awk_string1="/" awk_string2="/{print \$1}" window_in_focus_old="" while true do #ID ,    window_in_focus=`xprop -root |awk '/_NET_ACTIVE_WINDOW/ {print $5; exit;}'` #     ,     if [[ "$window_in_focus" -ne "$window_in_focus_old" ]] then window_in_focus_old=$window_in_focus #    list_of_progr=$(<$HOME/xsetwacom/programs) #     for name_of_progr in $list_of_progr do awk_string_result="$awk_string1$name_of_progr$awk_string2" #  ,        list_of_running_prog=`wmctrl -l | awk "${awk_string_result}"` #         - #    for running_progr in $list_of_running_prog do if [[ "$running_progr" -eq "$window_in_focus" ]] then $HOME/xsetwacom/$name_of_progr fi done done fi sleep 1 done 


In general, the installation algorithm is as follows:
  1. Copy the folder wacom-profile-switcher to your home directory.
  2. In the file programs we enter the names of those applications for which profiles are needed. The names must correspond to the inscriptions from the application windows, for example: gedit, LibreOffece, etc.
  3. For each such name, we create a file in which we make the necessary settings for the graphics tablet. File names must be written in the same way as in the file programs.
  4. Then you can either run the script if necessary, or throw it into autoload. Until the user switches from one window to another, the script will only check once per second if the window ID has changed in focus.


This entire two-wheeled sports simulator was tested on Linux Mint Petra and Wacom Pro M. In theory, it will work on other family members of this version. For all others, you will have to edit the script, because the buttons will not match.

I want tooltips and that's it!


And I still hope that Wacom will turn its attention to Linux and start releasing normal drivers, because sometimes there are not enough tooltips about the key assignment when you lightly tap on it, some gestures. And here you will not get off with one scenario.

For convenience, placed all the scripts on github

Source: https://habr.com/ru/post/212449/


All Articles