From: QueezyTheGreat <queezythegreat@gmail.com>
Date: Wed, 26 Jun 2013 17:33:16 +0000 (+0200)
Subject: Added install makefile and autorandr inotify monitor
X-Git-Tag: 1.0~149^2~4
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=74a310b76da7dbff1735387fecf4b1ba5f3f6cde;p=deb_pkgs%2Fautorandr.git

Added install makefile and autorandr inotify 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()