#!/usr/bin/python3
import dbus

session_bus = dbus.SessionBus()
kwin = session_bus.get_object('org.kde.KWin', '/org/kde/KWin/InputDevice')
kwin_props = dbus.Interface(kwin, dbus_interface='org.freedesktop.DBus.Properties')
for ev in kwin_props.Get('org.kde.KWin.InputDeviceManager', 'devicesSysNames'):
    evdev = session_bus.get_object('org.kde.KWin', f'/org/kde/KWin/InputDevice/{ev}')
    evdev_props = dbus.Interface(evdev, dbus_interface='org.freedesktop.DBus.Properties')

    is_touchpad = evdev_props.Get('org.kde.KWin.InputDevice', 'touchpad')
    if not is_touchpad:
        continue

    enabled = evdev_props.Get('org.kde.KWin.InputDevice', 'enabled')
    print(f'{ev!s}: {"dis" if enabled else "en"}abling')
    evdev_props.Set('org.kde.KWin.InputDevice', 'enabled', not enabled)

