3 Author: Tomasz Bogdal (a.k.a. QueezyTheGreat)
4 Home: https://github.com/queezythegreat/autorandr
5 License: This Source Code Form is subject to the terms of the
6 Mozilla Public License, v. 2.0
10 from pyinotify import ProcessEvent
12 #TODO: Fork off when started
13 #TODO: Add configuration file
14 #TODO: Add command line options
16 SYS_VIDEO_OUTPUTS='/sys/class/drm/'
17 DEFAULT_PROFILE='default'
18 AUTORANDR_CMD='autorandr --change --default %s' % DEFAULT_PROFILE
20 class VideoOutputMonitor(ProcessEvent):
21 """ Launch autorandr when video card output status is changed. """
23 def process_IN_ACCESS(self, event):
24 """ Handle IN_ACCESS events to `status` file. """
25 if event.name == 'status':
26 print 'Change status of %s' % os.path.basename(event.path)
27 os.system(AUTORANDR_CMD)
30 def register_video_cards(manager):
31 """ Register all video card ouptus for monitoring. """
32 if not os.path.exists(SYS_VIDEO_OUTPUTS):
35 for directory in os.listdir(SYS_VIDEO_OUTPUTS):
36 path = os.path.join(SYS_VIDEO_OUTPUTS, directory)
37 status = os.path.join(path, 'status')
38 if os.path.exists(status):
39 print 'Monitoring %s' % path
40 manager.add_watch(path, pyinotify.ALL_EVENTS)
43 # pyinotify.log.setLevel(10)
44 manager = pyinotify.WatchManager()
45 handler = VideoOutputMonitor()
46 notifier = pyinotify.Notifier(manager, default_proc_fun=handler)
48 register_video_cards(manager)
52 if __name__ == '__main__':