#!/bin/sh
# Copyright (C) 2016 Jarno Suni (8@iki.fi)

# Save the state of DPMS; rely on the output format of `xset q`.
xstate=$(xset q | awk '/^DPMS /{getline; printf "%s %s %s ", $2, $4, $6;
	getline; if($3=="Enabled"){print "+"}else{print "-"}exit}')
# Enable monitor power management
xset dpms 30 31 32
$*
exit_code=$?
# Restore DPMS state
xset dpms $(echo $xstate | cut -d' ' -f1-3)
xset $(echo $xstate | cut -d' ' -f4)dpms
exit $exit_code
