diff --git a/bin/plasma_toggle_tablet_mode b/bin/plasma_toggle_tablet_mode new file mode 100755 index 0000000..96c0226 --- /dev/null +++ b/bin/plasma_toggle_tablet_mode @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import subprocess +import gi + +gi.require_version('Gio', '2.0') +from gi.repository import Gio, GLib + +KDE_VERSION = 6 +OBJECT_PATH = '/kwinrc' +INTERFACE_NAME = 'org.kde.kconfig.notify' +SIGNAL_NAME = 'ConfigChanged' + +current_mode: str = subprocess.check_output([f"kreadconfig{KDE_VERSION}", "--file", "kwinrc", "--group", "Input", "--key", "TabletMode", "--default", "auto"]).decode(encoding='utf-8').strip() +if current_mode == "on": + subprocess.check_call([f"kwriteconfig{KDE_VERSION}", "--file", "kwinrc", "--group", "Input", "--key", "TabletMode", "off"]) +else: + subprocess.check_call([f"kwriteconfig{KDE_VERSION}", "--file", "kwinrc", "--group", "Input", "--key", "TabletMode", "on"]) + +connection = Gio.bus_get_sync(Gio.BusType.SESSION, None) +Gio.DBusConnection.emit_signal(connection, None, OBJECT_PATH, INTERFACE_NAME, SIGNAL_NAME, GLib.Variant.new_tuple(GLib.Variant('a{saay}', {'Input': [b'TabletMode']})))