Created
May 2, 2020 05:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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