Add tablet button mapping tools and xsetwacom compatibility test
User wants to test if xsetwacom can map Huion tablet buttons to keyboard shortcuts, which would eliminate the need for OpenTabletDriver. New tools: - detect-tablet-buttons.sh: Detect and test all tablet/pen button presses * Tests pen buttons (usually 2 buttons) * Tests tablet pad buttons (usually 6 buttons) * Tests if buttons are exposed as keyboard events * Shows which button numbers can be mapped - configure-tablet-buttons.sh: Configure button-to-keyboard mappings * Option 1: xbindkeys setup (recommended - works with any tablet) * Option 2: xinput button remapping (limited functionality) * Generates xbindkeys config with examples * Explains why xsetwacom doesn't work with Huion - test-xsetwacom-compatibility.sh: Test if xsetwacom actually works * Lists devices (xsetwacom can see them via xinput) * Tests property access (likely to fail) * Tests button configuration (likely to fail) * Provides clear diagnosis and alternatives Important: xsetwacom listing devices doesn't mean it can configure them. It requires wacom kernel driver, but Huion uses generic HID driver. The wacom driver is also blacklisted for OTD compatibility. If xsetwacom doesn't work, user should use xbindkeys + xdotool instead.
+631 · 3 files changed
-
configure-tablet-buttons.sh+257 −0 -
detect-tablet-buttons.sh+205 −0 -
test-xsetwacom-compatibility.sh+169 −0
@@ -0,0 +1,257 @@ +#!/bin/bash +# Configure tablet button mappings to keyboard shortcuts + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +BOLD='\033[1m' +NC='\033[0m' + +echo "==========================================" +echo "Tablet Button Configuration" +echo "==========================================" +echo "" + +# Check dependencies +MISSING_DEPS="" +if ! command -v xdotool &> /dev/null; then + MISSING_DEPS="$MISSING_DEPS xdotool" +fi + +if [ -n "$MISSING_DEPS" ]; then + echo -e "${YELLOW}Missing dependencies:$MISSING_DEPS${NC}" + echo "" + echo "Install with:" + echo " sudo pacman -S$MISSING_DEPS" + echo "" + read -p "Install now? [y/N]: " install_deps + if [[ "$install_deps" =~ ^[Yy]$ ]]; then + sudo pacman -S$MISSING_DEPS + else + echo "Please install dependencies and run this script again." + exit 1 + fi +fi + +echo "This script helps you map tablet buttons to keyboard shortcuts." +echo "" +echo "Note: xsetwacom ONLY works with Wacom tablets." +echo "Your Huion tablet needs xinput + xdotool instead." +echo "" + +# Find Huion devices +PEN_STYLUS_ID=$(xinput list | grep -i "HUION.*Pen stylus" | grep -v "floating" | grep -o 'id=[0-9]*' | cut -d= -f2) +PEN_STYLUS_NAME=$(xinput list | grep -i "HUION.*Pen stylus" | grep -v "floating" | sed 's/.*↳ //' | sed 's/id=.*//' | xargs) + +if [ -z "$PEN_STYLUS_ID" ]; then + echo -e "${RED}ERROR: Huion pen device not found${NC}" + echo "" + echo "Make sure:" + echo " - Tablet is connected" + echo " - Native HID is enabled (not using OTD)" + echo "" + echo "If using OTD, stop it first:" + echo " pkill otd-daemon" + echo " xinput enable 11 && xinput enable 24" + exit 1 +fi + +echo -e "${GREEN}Found device: $PEN_STYLUS_NAME (id=$PEN_STYLUS_ID)${NC}" +echo "" + +echo "==========================================" +echo "Configuration Method" +echo "==========================================" +echo "" +echo "Choose your configuration method:" +echo "" +echo "1) Use xbindkeys (recommended - more flexible)" +echo " - Can map buttons to any command or keyboard shortcut" +echo " - Persistent across reboots" +echo " - Works system-wide" +echo "" +echo "2) Use xinput + xdotool (simple)" +echo " - Map buttons to single keys" +echo " - Requires manual setup on each boot" +echo " - Good for testing" +echo "" +echo "3) Show button detection instructions" +echo "4) Exit" +echo "" +read -p "Choice [1-4]: " method + +case $method in + 1) + echo "" + echo "==========================================" + echo "xbindkeys Configuration" + echo "==========================================" + echo "" + + # Check if xbindkeys is installed + if ! command -v xbindkeys &> /dev/null; then + echo "Installing xbindkeys..." + sudo pacman -S xbindkeys + fi + + echo "Setting up xbindkeys for tablet button mapping..." + echo "" + echo "First, we need to detect your button numbers." + echo "Run this command and press each button:" + echo "" + echo " xinput test $PEN_STYLUS_ID" + echo "" + echo "Note the button numbers (e.g., 'button press 3')" + echo "" + read -p "Press Enter when you know your button numbers..." + + # Create xbindkeys config + XBINDKEYS_CONFIG="$HOME/.xbindkeysrc" + + if [ -f "$XBINDKEYS_CONFIG" ]; then + echo "" + echo "Backing up existing config to ~/.xbindkeysrc.bak" + cp "$XBINDKEYS_CONFIG" "$XBINDKEYS_CONFIG.bak" + fi + + cat > "$XBINDKEYS_CONFIG" << 'EOF' +# xbindkeys configuration for Huion tablet buttons +# Generated by configure-tablet-buttons.sh + +# Example pen button mappings +# Uncomment and modify these lines based on your button numbers + +# Pen button 1 (usually button 2 or 3) -> Ctrl+Z (undo) +#"xdotool key ctrl+z" +# b:3 + Release + +# Pen button 2 (usually button 8 or 9) -> Ctrl+Y (redo) +#"xdotool key ctrl+y" +# b:8 + Release + +# Tablet button examples: +# Button 1 -> B key (brush tool) +#"xdotool key b" +# b:1 + Release + +# Button 2 -> E key (eraser tool) +#"xdotool key e" +# b:2 + Release + +# Button 3 -> Ctrl+S (save) +#"xdotool key ctrl+s" +# b:10 + Release + +# To find your button numbers, run: +# xinput test DEVICE_ID +# and press the buttons + +# To reload config after editing: +# killall xbindkeys && xbindkeys +EOF + + echo "" + echo -e "${GREEN}✓ Created $XBINDKEYS_CONFIG${NC}" + echo "" + echo "Next steps:" + echo "1. Edit the config file:" + echo " nano ~/.xbindkeysrc" + echo "" + echo "2. Uncomment and modify the button mappings" + echo " Replace 'b:3' with your actual button number" + echo "" + echo "3. Start xbindkeys:" + echo " xbindkeys" + echo "" + echo "4. Test your buttons!" + echo "" + echo "5. Make xbindkeys start automatically:" + echo " Add 'xbindkeys' to your startup applications" + echo "" + ;; + + 2) + echo "" + echo "==========================================" + echo "xinput Button Mapping" + echo "==========================================" + echo "" + echo "This method uses xinput to remap buttons to other buttons." + echo "Then use xdotool to generate keystrokes." + echo "" + echo "Note: This is less flexible than xbindkeys." + echo "" + echo "Current button map for $PEN_STYLUS_NAME:" + xinput get-button-map "$PEN_STYLUS_ID" + echo "" + echo "Example: To disable pen button 3:" + echo " xinput set-button-map $PEN_STYLUS_ID 1 2 0 4 5 6 7 8 9" + echo "" + echo "To remap button 3 to button 2:" + echo " xinput set-button-map $PEN_STYLUS_ID 1 2 2 4 5 6 7 8 9" + echo "" + echo "However, this doesn't create keyboard shortcuts." + echo "Use xbindkeys (option 1) for keyboard shortcut mapping." + ;; + + 3) + echo "" + echo "==========================================" + echo "Button Detection Instructions" + echo "==========================================" + echo "" + echo "To find out which buttons your tablet has:" + echo "" + echo "1. Run xinput test for pen device:" + echo " xinput test $PEN_STYLUS_ID" + echo "" + echo "2. Press each button on your pen" + echo " Note the button numbers shown" + echo "" + echo "3. For tablet pad buttons, find the device:" + echo " xinput list | grep -i HUION" + echo "" + echo "4. Test the pad device ID with xinput test" + echo "" + echo "Common button mappings:" + echo " Button 1: Left click (don't remap)" + echo " Button 2: Middle click" + echo " Button 3: Right click (or first pen button)" + echo " Button 8-9: Additional pen buttons" + echo "" + ;; + + 4) + echo "Exiting." + exit 0 + ;; + + *) + echo "Invalid choice." + exit 1 + ;; +esac + +echo "" +echo "==========================================" +echo "Why not xsetwacom?" +echo "==========================================" +echo "" +echo "xsetwacom is ONLY for Wacom tablets using the wacom kernel driver." +echo "" +echo "Your Huion tablet uses:" +echo " - Generic Linux HID driver (for pressure/tilt)" +echo " - Or hid_uclogic driver (if enabled)" +echo "" +echo "Neither of these drivers work with xsetwacom." +echo "" +echo "The wacom driver is also blacklisted on your system" +echo "to allow OpenTabletDriver to work:" +echo " /etc/modprobe.d/99-opentabletdriver.conf" +echo "" +echo "Solutions for Huion tablets:" +echo " ✓ xbindkeys + xdotool (recommended)" +echo " ✓ xinput button remapping (limited)" +echo " ✓ OpenTabletDriver (has built-in button mapping)" +echo "" @@ -0,0 +1,205 @@ +#!/bin/bash +# Detect and test tablet/pen buttons for remapping + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +BOLD='\033[1m' +NC='\033[0m' + +echo "==========================================" +echo "Tablet Button Detection" +echo "==========================================" +echo "" + +echo "Searching for Huion tablet devices..." +echo "" + +# Find all Huion devices +HUION_DEVICES=$(xinput list | grep -i "HUION" | grep -v "floating") + +if [ -z "$HUION_DEVICES" ]; then + echo -e "${RED}No Huion devices found${NC}" + echo "" + echo "Make sure:" + echo " - Your tablet is connected" + echo " - Native devices are enabled (not using OTD)" + echo "" + echo "If using OTD, stop it first:" + echo " pkill otd-daemon" + echo " xinput enable 11 && xinput enable 24" + exit 1 +fi + +echo -e "${GREEN}Found Huion devices:${NC}" +echo "$HUION_DEVICES" | nl +echo "" + +# Extract device IDs and names +PEN_STYLUS_ID=$(echo "$HUION_DEVICES" | grep "Pen stylus" | grep -o 'id=[0-9]*' | cut -d= -f2) +PEN_STYLUS_NAME=$(echo "$HUION_DEVICES" | grep "Pen stylus" | sed 's/.*↳ //' | sed 's/id=.*//' | xargs) + +TABLET_PAD_ID=$(echo "$HUION_DEVICES" | grep -v "Pen" | grep -v "eraser" | grep -v "keyboard" | head -1 | grep -o 'id=[0-9]*' | cut -d= -f2) +TABLET_PAD_NAME=$(echo "$HUION_DEVICES" | grep -v "Pen" | grep -v "eraser" | grep -v "keyboard" | head -1 | sed 's/.*↳ //' | sed 's/id=.*//' | xargs) + +echo "==========================================" +echo "BUTTON DETECTION TEST" +echo "==========================================" +echo "" +echo "This will test button presses on your pen and tablet." +echo "We'll test each device separately." +echo "" + +# Test pen buttons +if [ -n "$PEN_STYLUS_ID" ]; then + echo -e "${BOLD}Testing: $PEN_STYLUS_NAME (id=$PEN_STYLUS_ID)${NC}" + echo "" + echo "Press the buttons on your PEN for 10 seconds..." + echo "You should see 'button press' and 'button release' events" + echo "" + echo "Look for lines like:" + echo " button press 3" + echo " button release 3" + echo "" + echo "The number tells you which button it is." + echo "" + read -p "Press Enter to start pen button test..." + echo "" + echo "==========================================" + + PEN_OUTPUT=$(timeout 10 xinput test "$PEN_STYLUS_ID" 2>&1) + + echo "$PEN_OUTPUT" + echo "" + echo "==========================================" + + # Analyze pen buttons + PEN_BUTTONS=$(echo "$PEN_OUTPUT" | grep "button press" | awk '{print $3}' | sort -n | uniq) + + if [ -n "$PEN_BUTTONS" ]; then + echo -e "${GREEN}✓ Detected pen buttons:${NC}" + for btn in $PEN_BUTTONS; do + echo " Button $btn" + done + echo "" + echo "You can remap these buttons to keyboard shortcuts!" + else + echo -e "${YELLOW}⚠ No pen button presses detected${NC}" + echo "Make sure you pressed the buttons during the test." + fi + echo "" +fi + +# Test tablet pad buttons +if [ -n "$TABLET_PAD_ID" ]; then + echo -e "${BOLD}Testing: $TABLET_PAD_NAME (id=$TABLET_PAD_ID)${NC}" + echo "" + echo "Press the buttons on your TABLET (not the pen) for 10 seconds..." + echo "You should see 'button press' and 'button release' events" + echo "" + read -p "Press Enter to start tablet button test..." + echo "" + echo "==========================================" + + TABLET_OUTPUT=$(timeout 10 xinput test "$TABLET_PAD_ID" 2>&1) + + echo "$TABLET_OUTPUT" + echo "" + echo "==========================================" + + # Analyze tablet buttons + TABLET_BUTTONS=$(echo "$TABLET_OUTPUT" | grep "button press" | awk '{print $3}' | sort -n | uniq) + + if [ -n "$TABLET_BUTTONS" ]; then + echo -e "${GREEN}✓ Detected tablet buttons:${NC}" + for btn in $TABLET_BUTTONS; do + echo " Button $btn" + done + echo "" + echo "You can remap these buttons to keyboard shortcuts!" + else + echo -e "${YELLOW}⚠ No tablet button presses detected${NC}" + echo "Make sure you pressed the buttons during the test." + echo "" + echo "Note: Some Huion tablets expose buttons as a separate keyboard device." + echo "Check if pressing buttons generates keyboard events instead." + fi + echo "" +fi + +# Check for keyboard device +KEYBOARD_DEVICE=$(xinput list | grep -i "HUION" | grep -i "keyboard") +if [ -n "$KEYBOARD_DEVICE" ]; then + KEYBOARD_ID=$(echo "$KEYBOARD_DEVICE" | grep -o 'id=[0-9]*' | cut -d= -f2) + KEYBOARD_NAME=$(echo "$KEYBOARD_DEVICE" | sed 's/.*↳ //' | sed 's/id=.*//' | xargs) + + echo -e "${BOLD}Found keyboard device: $KEYBOARD_NAME (id=$KEYBOARD_ID)${NC}" + echo "" + echo "Your tablet buttons might send keyboard events." + echo "Testing keyboard device for 10 seconds..." + echo "Press the TABLET buttons (not pen)..." + echo "" + read -p "Press Enter to start keyboard test..." + echo "" + echo "==========================================" + + KEYBOARD_OUTPUT=$(timeout 10 xinput test "$KEYBOARD_ID" 2>&1) + + echo "$KEYBOARD_OUTPUT" + echo "" + echo "==========================================" + + if echo "$KEYBOARD_OUTPUT" | grep -q "key press"; then + echo -e "${GREEN}✓ Tablet buttons send keyboard events!${NC}" + echo "" + echo "Your tablet buttons are already mapped to keyboard keys." + echo "You can use xev or xinput to see which keys they send," + echo "then remap them with xmodmap or xbindkeys if needed." + else + echo -e "${YELLOW}No keyboard events detected${NC}" + fi + echo "" +fi + +echo "==========================================" +echo "SUMMARY" +echo "==========================================" +echo "" + +if [ -n "$PEN_BUTTONS" ] || [ -n "$TABLET_BUTTONS" ]; then + echo -e "${GREEN}✓ Button remapping is possible!${NC}" + echo "" + echo "Detected buttons:" + + if [ -n "$PEN_BUTTONS" ]; then + echo " Pen buttons: $PEN_BUTTONS" + fi + + if [ -n "$TABLET_BUTTONS" ]; then + echo " Tablet buttons: $TABLET_BUTTONS" + fi + + echo "" + echo "Next steps:" + echo "1. Use xinput + xdotool to remap buttons to keyboard shortcuts" + echo "2. Or use xbindkeys for more complex mappings" + echo "3. Run ./configure-tablet-buttons.sh for automated setup" +else + echo -e "${YELLOW}Button detection unclear${NC}" + echo "" + echo "Possible reasons:" + echo " - Buttons might be keyboard events (already mapped)" + echo " - You didn't press buttons during the test" + echo " - Driver doesn't expose buttons properly" + echo "" + echo "Try running this script again and make sure to press" + echo "all buttons during the test periods." +fi + +echo "" +echo "Tablet button mapping info:" +echo " - xsetwacom: Only works with Wacom tablets (NOT Huion)" +echo " - xinput + xdotool: Works with any tablet, can map to keys" +echo " - xbindkeys: More flexible, can map to any command" +echo "" @@ -0,0 +1,169 @@ +#!/bin/bash +# Test if xsetwacom can actually configure Huion tablet buttons + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +BOLD='\033[1m' +NC='\033[0m' + +echo "==========================================" +echo "xsetwacom Compatibility Test" +echo "==========================================" +echo "" + +# Check if xsetwacom is installed +if ! command -v xsetwacom &> /dev/null; then + echo -e "${YELLOW}xsetwacom is not installed${NC}" + echo "" + echo "Install with:" + echo " sudo pacman -S xf86-input-wacom" + echo "" + read -p "Install now? [y/N]: " install + if [[ "$install" =~ ^[Yy]$ ]]; then + sudo pacman -S xf86-input-wacom + else + exit 1 + fi +fi + +echo "Testing xsetwacom with your Huion tablet..." +echo "" + +# List devices +echo -e "${BOLD}1. Listing devices with xsetwacom:${NC}" +echo "" +xsetwacom --list devices +echo "" + +# Try to get all properties from native Huion device +DEVICE_NAME="HUION Huion Tablet_G930L Pen stylus" + +echo "==========================================" +echo -e "${BOLD}2. Testing property access:${NC}" +echo "" +echo "Attempting to get all properties from:" +echo " $DEVICE_NAME" +echo "" + +if xsetwacom --get "$DEVICE_NAME" all 2>&1 | grep -q "error\|Error\|cannot"; then + echo -e "${RED}✗ FAILED: xsetwacom cannot access device properties${NC}" + echo "" + echo "Error output:" + xsetwacom --get "$DEVICE_NAME" all 2>&1 | head -20 + echo "" + echo "This confirms that xsetwacom CANNOT configure your Huion tablet." + echo "" + XSETWACOM_WORKS=false +else + echo -e "${GREEN}✓ SUCCESS: xsetwacom can read properties!${NC}" + echo "" + echo "Properties:" + xsetwacom --get "$DEVICE_NAME" all | head -20 + echo "" + XSETWACOM_WORKS=true +fi + +echo "" +echo "==========================================" +echo -e "${BOLD}3. Testing button configuration:${NC}" +echo "" + +if [ "$XSETWACOM_WORKS" = true ]; then + echo "Attempting to set Button 2 to 'key ctrl z'..." + echo "" + + if xsetwacom --set "$DEVICE_NAME" Button 2 "key ctrl z" 2>&1 | grep -q "error\|Error\|cannot"; then + echo -e "${RED}✗ FAILED: Cannot set button mapping${NC}" + echo "" + xsetwacom --set "$DEVICE_NAME" Button 2 "key ctrl z" 2>&1 + echo "" + BUTTON_MAPPING_WORKS=false + else + echo -e "${GREEN}✓ SUCCESS: Button mapping set!${NC}" + echo "" + echo "Verify it worked:" + xsetwacom --get "$DEVICE_NAME" Button 2 + echo "" + BUTTON_MAPPING_WORKS=true + fi +else + echo "Skipping button test since property access failed." + BUTTON_MAPPING_WORKS=false +fi + +echo "" +echo "==========================================" +echo "RESULTS" +echo "==========================================" +echo "" + +if [ "$XSETWACOM_WORKS" = true ] && [ "$BUTTON_MAPPING_WORKS" = true ]; then + echo -e "${GREEN}✓✓✓ EXCELLENT NEWS! ✓✓✓${NC}" + echo "" + echo "xsetwacom CAN configure your Huion tablet!" + echo "" + echo "This means you can use xsetwacom to:" + echo " - Map pen buttons to keyboard shortcuts" + echo " - Configure pressure curves" + echo " - Set tablet area" + echo " - All without needing OpenTabletDriver!" + echo "" + echo "You do NOT need OTD if xsetwacom works." + echo "" + echo "Next steps:" + echo " 1. Map your buttons:" + echo " xsetwacom --set \"$DEVICE_NAME\" Button 2 \"key ctrl z\"" + echo " xsetwacom --set \"$DEVICE_NAME\" Button 3 \"key e\"" + echo "" + echo " 2. Make mappings permanent:" + echo " Create a startup script or use ~/.xinitrc" + echo "" + echo " 3. See all options:" + echo " xsetwacom --list parameters" + echo "" +else + echo -e "${RED}✗ xsetwacom CANNOT configure your Huion tablet${NC}" + echo "" + echo "Reasons:" + echo " - Huion tablets require wacom kernel driver for xsetwacom" + echo " - Your system uses generic HID driver instead" + echo " - wacom driver is blacklisted for OTD compatibility" + echo "" + echo "Alternatives for button mapping:" + echo "" + echo "1. xbindkeys + xdotool (RECOMMENDED)" + echo " - Works with any device" + echo " - Very flexible" + echo " - Run: ./configure-tablet-buttons.sh" + echo "" + echo "2. OpenTabletDriver" + echo " - Has built-in button mapping via otd-gui" + echo " - But you've had issues with it" + echo "" + echo "3. Enable hid_uclogic driver (experimental)" + echo " - Remove wacom/hid_uclogic blacklist" + echo " - Might work with xsetwacom" + echo " - But will break OTD if you ever want to use it" + echo "" +fi + +echo "" +echo "==========================================" +echo "Technical Details" +echo "==========================================" +echo "" + +echo "Kernel driver in use:" +udevadm info /dev/input/event* 2>/dev/null | grep -A 10 "HUION" | grep "DRIVER" | head -1 +echo "" + +echo "Modprobe blacklist:" +if [ -f /etc/modprobe.d/99-opentabletdriver.conf ]; then + cat /etc/modprobe.d/99-opentabletdriver.conf +else + echo "No OTD blacklist found" +fi + +echo ""