/usr/bin/caffeinate is in caffeine 2.9.4-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #!/usr/bin/python3
#
# Copyright © 2015-2016 Reuben Thomas
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import argparse
import signal
from subprocess import run
import pkg_resources
from Xlib import display
sys.tracebacklimit = None
PROGRAM_NAME = "caffeinate"
VERSION = pkg_resources.require("caffeine")[0].version
def die(err):
sys.exit(PROGRAM_NAME + ': ' + err)
# Handle command line arguments
parser = argparse.ArgumentParser(prog=PROGRAM_NAME, description='Inhibit desktop idleness for the duration of COMMAND')
parser.add_argument('COMMAND', help='command to run')
parser.add_argument('ARGUMENT', nargs='*', help='arguments to COMMAND', default=None)
parser.add_argument('-V', '--version', action='version', version=PROGRAM_NAME + ' ' + VERSION)
args = parser.parse_args()
def make_unmapped_window(wm_name):
screen = display.Display().screen()
window = screen.root.create_window(0, 0, 1, 1, 0, screen.root_depth)
window.set_wm_name(wm_name)
window.set_wm_protocols([])
return window
# Create window to use with xdg-screensaver
window = make_unmapped_window("caffeinate")
wid = hex(window.id)
# Catch signals, to do our best to ensure inhibition is removed
def signal_action(*args):
release()
sys.exit(1)
def release():
if run(['xdg-screensaver', 'resume', wid]).returncode != 0:
die("could not uninhibit desktop idleness")
for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGHUP]:
signal.signal(sig, signal_action)
# Run command, bracketed by xdg-screensaver suspend/resume
if run(['xdg-screensaver', 'suspend', wid]).returncode != 0:
die("could not inhibit desktop idleness")
run([args.COMMAND] + args.ARGUMENT)
release()
|