Add screen layout manager

master
Lars Vierbergen 8 years ago
parent 211b84f16c
commit e7ebf5c245
  1. 2
      daemon.py
  2. 58
      modules/screenlayout.py

@ -6,11 +6,13 @@ from modules.audiooutput import PulseCtlDefaultSinkCycleAction
from modules.audiooutput import naming_map, sink_filter, sink_input_filter from modules.audiooutput import naming_map, sink_filter, sink_input_filter
from modules.cycle import * from modules.cycle import *
from modules.toggle import CommandToggleControl from modules.toggle import CommandToggleControl
from modules.screenlayout import ScreenLayoutCycleAction
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
logging.getLogger('modules.core').setLevel(logging.WARNING) logging.getLogger('modules.core').setLevel(logging.WARNING)
modules.Application( modules.Application(
CycleControl(ScreenLayoutCycleAction()),
modules.GroupedControl( modules.GroupedControl(
modules.CaffeineControl(), modules.CaffeineControl(),
modules.RedshiftControl(), modules.RedshiftControl(),

@ -0,0 +1,58 @@
from collections import OrderedDict
from .cycle import OrderedDictCycleAction
from .util import process_reaper
import logging
import os
import subprocess
import argparse
logger = logging.getLogger(__name__)
class ScreenLayoutCycleAction(OrderedDictCycleAction):
def __init__(self):
self.__od = OrderedDict()
super().__init__(self.__od)
self.__inhibited = True
def configure(self, argument_parser: argparse.ArgumentParser):
argument_parser.add_argument('--screenlayout-dir', help='Directory containing screenlayout shell files.', type=str)
@property
def enabled(self):
return self.args.screenlayout_dir is not None
def bind_arguments(self, args):
super().bind_arguments(args)
self.__load_layouts(args.screenlayout_dir)
def next(self):
super().next()
self.__set_screen_layout(next_layout=self.next)
def prev(self):
super().prev()
self.__set_screen_layout(next_layout=self.prev)
def periodic(self):
if self.__inhibited:
self.__inhibited = False
self.__set_screen_layout(next_layout=self.next)
return True
return False
def __load_layouts(self, directory):
entries = os.scandir(directory)
for entry in entries:
if entry.is_file():
logger.debug('Found file %s', entry.path)
self.__od[entry.path] = entry.name
def __set_screen_layout(self, next_layout):
if self.__inhibited:
logger.info('Screen layout is inhibited.')
return
logger.info('Starting screenlayout %s', self.current)
layout_proc = subprocess.Popen([self.current])
if layout_proc.wait():
logger.warning('Screenlayout failed, continueing to next layout.')
next_layout()
Loading…
Cancel
Save