Skip to content

Commit

Permalink
add ipc-scripts/input.py (#2216)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 authored Mar 13, 2024
1 parent ea3a09b commit b134f11
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions ipc-scripts/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import wayfire_socket as ws
import os
import argparse
import tabulate

# Usage:
# input.py list-inputs
# input.py enable <id>
# input.py disable <id>

# argparse is used to parse the command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('action', choices=['list-inputs', 'enable', 'disable'])
parser.add_argument('device', nargs='?', default=None)
args = parser.parse_args()

if args.action == 'list-inputs' and args.device is not None:
print('Invalid usage, no arguments allowed when listing inputs!')
exit(-1)

if args.device is None and args.action != 'list-inputs':
print('Invalid usage, an input id >= 0 is required!')
exit(-1)

addr = os.getenv('WAYFIRE_SOCKET')
sock = ws.WayfireSocket(addr)

devices = sock.list_input_devices()

def find_device_id(name_or_id_or_type):
for dev in devices:
if dev['name'] == name_or_id_or_type or str(dev['id']) == name_or_id_or_type or dev['type'] == name_or_id_or_type:
return dev['id']
return None

if args.action == 'list-inputs':

headers = ["Name", "ID", "Type", "Vendor/Product", "Enabled"]
data = []
for dev in devices:
data.append([
dev['name'],
str(dev['id']),
dev['type'],
str(dev['vendor']) + ', ' + str(dev['product']),
dev['enabled']
])

print(tabulate.tabulate(data, headers))

elif args.action == 'enable':
print(sock.configure_input_device(find_device_id(args.device), True))
elif args.action == 'disable':
print(sock.configure_input_device(find_device_id(args.device), False))

0 comments on commit b134f11

Please sign in to comment.