summaryrefslogtreecommitdiffstats
path: root/pts-core/modules/toggle_screensaver.php
blob: b61dccc865c6f835bea89e2298707476f7463e35 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php

/*
	Phoronix Test Suite
	URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
	Copyright (C) 2008, Phoronix Media
	Copyright (C) 2004-2008, Michael Larabel
	toggle_screensaver.php: A module to toggle the screensaver while tests are running on GNOME

	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/>.
*/

class toggle_screensaver extends pts_module_interface
{
	const module_name = "Toggle Screensaver";
	const module_version = "1.0.1";
	const module_description = "This module toggles the system's screensaver while the Phoronix Test Suite is running. At this time, the GNOME and KDE screensavers are supported.";
	const module_author = "Phoronix Media";

	static $screensaver_halted = FALSE;
	static $gnome_screensaver_halted = FALSE;
	static $kde_screensaver_halted = FALSE;

	public static function __startup()
	{
		$halt_screensaver = trim(getenv("HALT_SCREENSAVER"));
		if(!empty($halt_screensaver) && !pts_string_bool($halt_screensaver))
			return;

		// GNOME Screensaver?
		$is_gnome_screensaver_enabled = trim(shell_exec("gconftool -g /apps/gnome-screensaver/idle_activation_enabled 2>&1"));

		if($is_gnome_screensaver_enabled == "true")
		{
			// Stop the GNOME Screensaver
			shell_exec("gconftool --type bool --set /apps/gnome-screensaver/idle_activation_enabled false 2>&1");
			self::$gnome_screensaver_halted = TRUE;
		}
		else
		{
			// KDE Screensaver?
			$is_kde_screensaver_enabled = trim(shell_exec("dcop kdesktop KScreensaverIface isEnabled 2>&1"));

			if($is_kde_screensaver_enabled == "true")
			{
				// Stop the KDE Screensaver
				shell_exec("dcop kdesktop KScreensaverIface enable false 2>&1");
				self::$kde_screensaver_halted = TRUE;
			}
		}

		if(self::$gnome_screensaver_halted || self::$kde_screensaver_halted)
			self::$screensaver_halted = TRUE;
	}
	public static function __shutdown()
	{
		if(self::$gnome_screensaver_halted == TRUE)
		{
			// Restore the GNOME Screensaver
			shell_exec("gconftool --type bool --set /apps/gnome-screensaver/idle_activation_enabled true 2>&1");
		}
		else if(self::$kde_screensaver_halted == TRUE)
		{
			// Restore the KDE Screensaver
			shell_exec("dcop kdesktop KScreensaverIface enable true 2>&1");
		}
	}
	public static function __pre_option_process()
	{
		if(!self::$screensaver_halted)
		{
			shell_exec("xdg-screensaver reset 2>&1");
		}
	}
	public static function __pre_run_process()
	{
		if(!self::$screensaver_halted)
		{
			shell_exec("xdg-screensaver reset 2>&1");
		}
	}
	public static function __pre_test_run()
	{
		if(!self::$screensaver_halted)
		{
			shell_exec("xdg-screensaver reset 2>&1");
		}
	}
	public static function __post_run_process()
	{
		if(!self::$screensaver_halted)
		{
			shell_exec("xdg-screensaver reset 2>&1");
		}
	}
}

?>