Skip to content

Instantly share code, notes, and snippets.

@cetaSYN
Created May 2, 2020 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cetaSYN/d5e74fd90cb991294498632c6b3d9f7d to your computer and use it in GitHub Desktop.
Save cetaSYN/d5e74fd90cb991294498632c6b3d9f7d to your computer and use it in GitHub Desktop.
Configure a Wacom tablet for use with a single screen and Touch disabled
#!/usr/bin/env python3
"""Configure a Wacom tablet for use with a single screen and Touch disabled"""
import subprocess
def main():
screens = [s for s in get_selector_next(
subprocess.check_output(["xrandr"]).decode("UTF8"),
u"connected",
skip=[u"primary"]
)]
# Choose screen to focus on
selection = ""
while not selection.isdigit():
for i in range(len(screens)):
print(f"[{i}]: {screens[i]}")
selection = input("Select a focus screen: ")
# Set settings
for id in get_selector_next(
subprocess.check_output(["xsetwacom", "--list"]).decode("UTF8"),
u"id:"
):
subprocess.call(["xsetwacom", "set", id, "touch", "off"])
subprocess.call(["xsetwacom", "set", id, "MapToOutput", screens[int(selection)]])
def get_selector_next(p_str, sel, skip=None):
"""Returns the value following a selector in a process output string
@param p_str String to search within; intended for subprocess output but not exclusive
@param sel String to search for, returning the item that follows
@param skip List of strings to skip before the item to return
@return The item in a string following sel
"""
next_index = False
for x in p_str.split():
if x == sel:
next_index = True
continue
if next_index is True:
if skip is not None and x in skip:
continue
next_index = False
yield x
next_index = False
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment