Created
November 2, 2022 21:48
-
-
Save UltiRequiem/b4569c117a5c508eb7cd35666813aadb to your computer and use it in GitHub Desktop.
monitor setup py
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
from os import popen, system | |
PRINCIPAL_MONITOR = popen("xrandr --query | grep primary").read().split()[0] | |
class Monitor: | |
def __init__(self, name, side): | |
self.name = name | |
self.side = side | |
def is_conected(self) -> bool: | |
return "connected" in popen(f"xrandr --query | grep {self.name}").read() | |
def activate(self) -> None: | |
command = ( | |
f"xrandr --output {self.name} --auto --{self.side}-of {PRINCIPAL_MONITOR}" | |
) | |
for func in [system, print]: | |
func(command) | |
def activate_all_monitors(monitors: tuple[Monitor] | list[Monitor]) -> None: | |
for monitor in monitors: | |
if monitor.is_conected(): | |
monitor.activate() | |
if __name__ == "__main__": | |
activate_all_monitors([Monitor("HDMI-1", "left")]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment