Skip to content

Instantly share code, notes, and snippets.

@yjlcoder
Last active February 19, 2024 18:14
Show Gist options
  • Select an option

  • Save yjlcoder/f093301cbc7ef7a67db7faa95d8d4be9 to your computer and use it in GitHub Desktop.

Select an option

Save yjlcoder/f093301cbc7ef7a67db7faa95d8d4be9 to your computer and use it in GitHub Desktop.
Setup Wacom tablet for multi displays

This script configured wacom tablet to confine it in a sinle display

#!env python3
import argparse
from typing import List
import subprocess
import re
import sys
class bcolors:
OKGREEN = '\033[92m'
OKLESSIMPORTANT = '\033[35m'
ENDC = '\033[0m'
BOLD = '\033[1m'
ITALIC = '\33[3m'
UNDERLINE = '\033[4m'
parser = argparse.ArgumentParser()
parser.add_argument('--display', required=False, default='HEAD-0')
args = parser.parse_args()
def log(message: str, **kwargs):
print(f"{bcolors.OKGREEN}{bcolors.BOLD}{bcolors.UNDERLINE}{message}{bcolors.ENDC}", **kwargs)
def quoted_log(message: str, **kwargs):
print(f"{bcolors.OKLESSIMPORTANT}{bcolors.ITALIC}{message}{bcolors.ENDC}", **kwargs)
def get_device_ids() -> List[str]:
device_ids = []
output = subprocess.check_output(['xsetwacom', '--list', 'devices']).decode('utf-8')
for line in output.splitlines():
match = re.search('id: (\d+)', line)
if match is None:
print(f'Cannot find id in line: {line}', output=sys.stderr)
else:
device_ids.append(match.group(1))
return device_ids
def configure_device(device_id: str, display: str):
log(f"Configuring {device_id} to display {display}")
output = subprocess.check_output(['xsetwacom', '-v', '--set', device_id, 'MapToOutput', display], stderr=subprocess.STDOUT).decode('utf-8')
quoted_output = '\n'.join([f" > {line}" for line in output.splitlines() if line.strip()])
quoted_log(quoted_output)
def main():
device_ids = get_device_ids()
log(f"Device IDs: {' '.join(device_ids)}")
for device_id in device_ids:
configure_device(device_id, args.display)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment