Commit 36e0772b authored by onny's avatar onny
Browse files

add code

parents
import subprocess
import re
class Screen:
def __init__(self, name, state=None):
self.name = name
self._state = state
@property
def state(self):
return self._state
@state.setter
def state(self, value):
if self._state != None and value:
subprocess.run(['wlr-randr', '--output', self.name, '--on'])
else:
subprocess.run(['wlr-randr', '--output', self.name, '--off'])
self._state = value
class wlScreens:
def __init__(self):
self.screens = []
result = subprocess.run(['wlr-randr'], stdout=subprocess.PIPE)
result = result.stdout.decode('utf-8')
re_search_pat = r'([A-Z]+-\d) '
match = re.findall(re_search_pat, result)
for screenName in match:
screen = Screen(screenName)
self.screens.append(screen)
re_search_pat = r'Enabled: ([a-z]+)'
match = re.findall(re_search_pat, result)
for num, state in enumerate(match):
screen = self.screens[num]
if (state == "yes"):
screen.state = True
else:
screen.state = False
def toggleModes(self):
if (len(self.screens) == 2):
if (self.screens[0].state == True and self.screens[1].state == True):
self.screens[0].state = False
elif (self.screens[0].state == False and self.screens[1].state == True):
self.screens[1].state = False
self.screens[0].state = True
elif (self.screens[0].state == True and self.screens[1].state == False):
self.screens[1].state = True
if (len(self.screens) == 1):
if (self.screens[0].state == True):
self.screens[0].state = False
else:
self.screens[0].state = True
def __len__(self):
return len(self.screens)
def __str__(self):
return str(self.screens)
def __getitem__(self, key):
return self.screens[key]
screens = wlScreens()
screens.toggleModes()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment