Created
January 18, 2024 22:25
-
-
Save rubdos/d34ee20152bf41726ca658525b070035 to your computer and use it in GitHub Desktop.
sway automatic scaling on dock (for my Framework)
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
[Unit] | |
Description=Sway scaling daemon | |
[Service] | |
Environment=HOME=/home/rsmet/ | |
ExecStart=/usr/bin/python /home/rsmet/.local/bin/sway-scaling-daemon.py | |
Restart=always | |
ExecStartPost=/bin/sleep 1 | |
[Install] | |
WantedBy=default.target |
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 | |
import pyudev | |
import subprocess | |
def main(): | |
context = pyudev.Context() | |
monitor = pyudev.Monitor.from_netlink(context) | |
monitor.filter_by(subsystem='usb') | |
monitor.start() | |
devpath = None | |
for device in iter(monitor.poll, None): | |
if devpath is None: | |
if "ID_VENDOR_ID" not in device: | |
print("Ignoring", device) | |
continue | |
if "ID_MODEL_ID" not in device: | |
print("Ignoring", device.properties["ID_VENDOR_ID"]) | |
continue | |
if device.properties["ID_VENDOR_ID"] != u'2109' or device.properties["ID_MODEL_ID"] != u'2822': | |
print("Ignoring", device.properties["ID_VENDOR_ID"], device.properties["ID_MODEL_ID"]) | |
continue | |
elif device.action != "remove": | |
continue | |
elif device.properties["DEVPATH"] != devpath: | |
continue | |
if device.action == "add": | |
devpath = device.properties["DEVPATH"] | |
scale = "1.5" | |
elif device.action == "remove": | |
devpath = None | |
scale = "1.3" | |
else: | |
print(device.action) | |
continue | |
print("Setting scale to", scale, "saving dev", devpath) | |
# I can add more logic here, to run different scripts for different devices. | |
subprocess.call(["/usr/bin/swaymsg", "output", "eDP-1", "scale", scale]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment