From 74a310b76da7dbff1735387fecf4b1ba5f3f6cde Mon Sep 17 00:00:00 2001 From: QueezyTheGreat Date: Wed, 26 Jun 2013 19:33:16 +0200 Subject: [PATCH 1/5] 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() From 82a1046663291b69499543c17bae9bccd21f6c53 Mon Sep 17 00:00:00 2001 From: QueezyTheGreat Date: Wed, 26 Jun 2013 19:45:31 +0200 Subject: [PATCH 2/5] Updated Makefile, minor change to inotify monitor --- Makefile | 2 +- autorandr_monitor | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4d871ad..8a45be5 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +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/ + ln -sf /usr/bin/autorandr /usr/bin/auto-disper #install -m pm-utils/40autorandr /etc/pm/power.d/ diff --git a/autorandr_monitor b/autorandr_monitor index e1e5259..245b4dd 100755 --- a/autorandr_monitor +++ b/autorandr_monitor @@ -4,8 +4,9 @@ import pyinotify from pyinotify import ProcessEvent SYS_VIDEO_OUTPUTS='/sys/class/drm/card0/' +SYS_VIDEO_OUTPUTS='/sys/class/drm/' -DEFAULT_PROFILE='mobile' +DEFAULT_PROFILE='default' AUTORANDR_CMD='autorandr --change --default %s' % DEFAULT_PROFILE class VideoOutputMonitor(ProcessEvent): From 0f31c5e5b6d772510cdd46eea4afa0878e154864 Mon Sep 17 00:00:00 2001 From: QueezyTheGreat Date: Wed, 26 Jun 2013 20:09:14 +0200 Subject: [PATCH 3/5] Minor code refactoring --- Makefile | 3 ++- Xsession.d/autorandr | 3 +++ autorandr_monitor | 30 ++++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 Xsession.d/autorandr diff --git a/Makefile b/Makefile index 8a45be5..a8ee74a 100644 --- a/Makefile +++ b/Makefile @@ -4,4 +4,5 @@ install: install -m 774 autorandr_monitor /usr/bin/ install -m 644 bash_completion/autorandr /etc/bash_completion.d/ ln -sf /usr/bin/autorandr /usr/bin/auto-disper - #install -m pm-utils/40autorandr /etc/pm/power.d/ + #install -m 644 /etc/X11/Xsession.d/ + #install -m 644 pm-utils/40autorandr /etc/pm/power.d/ diff --git a/Xsession.d/autorandr b/Xsession.d/autorandr new file mode 100644 index 0000000..06e9d2b --- /dev/null +++ b/Xsession.d/autorandr @@ -0,0 +1,3 @@ +# -*- sh -*- + +autorandr_mointor > /tmp/autorandr_monitor & diff --git a/autorandr_monitor b/autorandr_monitor index 245b4dd..6f369bb 100755 --- a/autorandr_monitor +++ b/autorandr_monitor @@ -1,23 +1,34 @@ #!/usr/bin/env python +"""" +Author: Tomasz Bogdal (a.k.a. QueezyTheGreat) +Home: https://github.com/queezythegreat/autorandr +License: This Source Code Form is subject to the terms of the + Mozilla Public License, v. 2.0 +""" import os import pyinotify from pyinotify import ProcessEvent -SYS_VIDEO_OUTPUTS='/sys/class/drm/card0/' -SYS_VIDEO_OUTPUTS='/sys/class/drm/' +#TODO: Fork off when started +#TODO: Add configuration file +#TODO: Add command line options +SYS_VIDEO_OUTPUTS='/sys/class/drm/' DEFAULT_PROFILE='default' AUTORANDR_CMD='autorandr --change --default %s' % DEFAULT_PROFILE class VideoOutputMonitor(ProcessEvent): + """ Launch autorandr when video card output status is changed. """ def process_IN_ACCESS(self, event): + """ Handle IN_ACCESS events to `status` file. """ if event.name == 'status': print 'Change status of %s' % os.path.basename(event.path) os.system(AUTORANDR_CMD) def register_video_cards(manager): + """ Register all video card ouptus for monitoring. """ if not os.path.exists(SYS_VIDEO_OUTPUTS): return @@ -28,12 +39,15 @@ def register_video_cards(manager): print 'Monitoring %s' % path manager.add_watch(path, pyinotify.ALL_EVENTS) -# pyinotify.log.setLevel(10) +def main(): + # pyinotify.log.setLevel(10) + manager = pyinotify.WatchManager() + handler = VideoOutputMonitor() + notifier = pyinotify.Notifier(manager, default_proc_fun=handler) -manager = pyinotify.WatchManager() -handler = VideoOutputMonitor() -notifier = pyinotify.Notifier(manager, default_proc_fun=handler) + register_video_cards(manager) -register_video_cards(manager) + notifier.loop() -notifier.loop() +if __name__ == '__main__': + main() From c71e1097d5f4b765579c434f20b49044519dc9d2 Mon Sep 17 00:00:00 2001 From: QueezyTheGreat Date: Wed, 26 Jun 2013 20:31:39 +0200 Subject: [PATCH 4/5] Minor fixes and improvements --- Makefile | 6 +++--- Xsession.d/autorandr | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a8ee74a..1bbfa0b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ install: - install -m 774 autorandr /usr/bin/ - install -m 774 autorandr_monitor /usr/bin/ + install -m 775 autorandr /usr/bin/ + install -m 775 autorandr_monitor /usr/bin/ install -m 644 bash_completion/autorandr /etc/bash_completion.d/ ln -sf /usr/bin/autorandr /usr/bin/auto-disper - #install -m 644 /etc/X11/Xsession.d/ + install -m 644 Xsession.d/autorandr /etc/X11/Xsession.d/45autorandr #install -m 644 pm-utils/40autorandr /etc/pm/power.d/ diff --git a/Xsession.d/autorandr b/Xsession.d/autorandr index 06e9d2b..b53f10c 100644 --- a/Xsession.d/autorandr +++ b/Xsession.d/autorandr @@ -1,3 +1,4 @@ # -*- sh -*- -autorandr_mointor > /tmp/autorandr_monitor & +/usr/bin/autorandr --change --default default +/usr/bin/autorandr_monitor &> /tmp/autorandr_monitor & From 2509ac3b83b4b4ee16c4a4af34b0138a2c95a3c6 Mon Sep 17 00:00:00 2001 From: QueezyTheGreat Date: Wed, 26 Jun 2013 20:40:29 +0200 Subject: [PATCH 5/5] Minor fixes and improvements --- Makefile | 2 +- Xsession.d/autorandr | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1bbfa0b..49d598e 100644 --- a/Makefile +++ b/Makefile @@ -4,5 +4,5 @@ install: install -m 775 autorandr_monitor /usr/bin/ install -m 644 bash_completion/autorandr /etc/bash_completion.d/ ln -sf /usr/bin/autorandr /usr/bin/auto-disper - install -m 644 Xsession.d/autorandr /etc/X11/Xsession.d/45autorandr + install -m 644 Xsession.d/autorandr /etc/X11/Xsession.d/99zautorandr #install -m 644 pm-utils/40autorandr /etc/pm/power.d/ diff --git a/Xsession.d/autorandr b/Xsession.d/autorandr index b53f10c..d0b568a 100644 --- a/Xsession.d/autorandr +++ b/Xsession.d/autorandr @@ -1,4 +1,3 @@ # -*- sh -*- -/usr/bin/autorandr --change --default default /usr/bin/autorandr_monitor &> /tmp/autorandr_monitor &