aboutsummaryrefslogtreecommitdiffstats
path: root/.i3/py3status/backup/dpms.py
blob: 783c53c8bcad4d48ecbcfd56c5ed52c70d4ab78b (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
from os import system


class Py3status:
    """
    This module allows activation and deactivation
    of DPMS (Display Power Management Signaling)
    by clicking on 'DPMS' in the status bar.

    Written and contributed by @tasse:
        Andre Doser <dosera AT tf.uni-freiburg.de>
    """
    def __init__(self):
        """
        Detect current state on start.
        """
        self.run = system('xset -q | grep -iq "DPMS is enabled"') == 0

    def dpms(self, i3status_output_json, i3status_config):
        """
        Display a colorful state of DPMS.
        """
        result = {
            'full_text': 'DPMS',
            'name': 'dpms'
        }
        if self.run:
            result['color'] = i3status_config['color_good']
        else:
            result['color'] = i3status_config['color_bad']
        return (0, result)

    def on_click(self, json, i3status_config, event):
        """
        Enable/Disable DPMS on left click.
        """
        if event['button'] == 1:
            if self.run:
                self.run = False
                system("xset -dpms")
            else:
                self.run = True
                system("xset +dpms")
            system("killall -USR1 py3status")