From 74a310b76da7dbff1735387fecf4b1ba5f3f6cde Mon Sep 17 00:00:00 2001 From: QueezyTheGreat Date: Wed, 26 Jun 2013 19:33:16 +0200 Subject: [PATCH] Added install makefile and autorandr inotify monitor --- Makefile | 7 +++++++ autorandr_monitor | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Makefile create mode 100755 autorandr_monitor diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4d871ad --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ + +install: + install auto-disper /usr/bin/ + install -m 774 autorandr /usr/bin/ + install -m 774 autorandr_monitor /usr/bin/ + install -m 644 bash_completion/autorandr /etc/bash_completion.d/ + #install -m pm-utils/40autorandr /etc/pm/power.d/ diff --git a/autorandr_monitor b/autorandr_monitor new file mode 100755 index 0000000..e1e5259 --- /dev/null +++ b/autorandr_monitor @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import os +import pyinotify +from pyinotify import ProcessEvent + +SYS_VIDEO_OUTPUTS='/sys/class/drm/card0/' + +DEFAULT_PROFILE='mobile' +AUTORANDR_CMD='autorandr --change --default %s' % DEFAULT_PROFILE + +class VideoOutputMonitor(ProcessEvent): + + def process_IN_ACCESS(self, event): + if event.name == 'status': + print 'Change status of %s' % os.path.basename(event.path) + os.system(AUTORANDR_CMD) + + +def register_video_cards(manager): + if not os.path.exists(SYS_VIDEO_OUTPUTS): + return + + for directory in os.listdir(SYS_VIDEO_OUTPUTS): + path = os.path.join(SYS_VIDEO_OUTPUTS, directory) + status = os.path.join(path, 'status') + if os.path.exists(status): + print 'Monitoring %s' % path + manager.add_watch(path, pyinotify.ALL_EVENTS) + +# pyinotify.log.setLevel(10) + +manager = pyinotify.WatchManager() +handler = VideoOutputMonitor() +notifier = pyinotify.Notifier(manager, default_proc_fun=handler) + +register_video_cards(manager) + +notifier.loop() -- 2.39.2