ultrabug / py3status

py3status is an extensible i3status wrapper written in python
https://ultrabug.github.io/py3status/
BSD 3-Clause "New" or "Revised" License
890 stars 261 forks source link

picom module would be nice #2084

Closed HeCodes2Much closed 2 years ago

HeCodes2Much commented 2 years ago

Is your feature request related to a problem? Please describe. No its not about an issue with anything.

Your py3status version py3status version 3.40 (python 3.9.9) on i3

Describe the solution you'd like a module that can check if picom is running on the system or not and have a click event to enable or disable it using 'on_click'

Describe alternatives you've considered

external_script 1 {
    format = "<span background='#6C77BB'>   </span><span background='#C4C7C5'> {output} </span>"
    script_path = "~/.config/polybar/scripts/picom.sh"
    on_click 1 = "exec ~/.config/polybar/scripts/picom-toggle.sh"
}

with the scripts being

picom.sh

if pgrep -x "picom" > /dev/null
then
    echo "Loaded"
else
    echo "UnLoaded"
f

picom-toggle.sh

if pgrep -x "picom" > /dev/null
then
    killall picom
else
    picom -CGb --experimental-backend --config ~/.config/i3/picom.conf
fi

Additional context if this can be done easier with just a script please let me know in the comments as this doesn't seem to work after being clicked it takes 15 seconds to reload

HeCodes2Much commented 2 years ago

if this is easy enough to have as a custom module please can you show an example how i could do this if it doesn't need to be part of the base project please :)

HeCodes2Much commented 2 years ago

Code

# -*- coding: utf-8 -*-
"""
Example module that demonstrates status string placeholders

Configuration parameters:
    format: Initial format to use
        (default '{button}')
    format_clicked: Display format to use when we are clicked
        (default '{button}')

Format placeholders:
    {button} The button that was pressed
"""

import os

class Py3status:
    format = '{button}'
    format_clicked = '{button}'

    def __init__(self):
        output = os.popen("pgrep -x picom").read()
        if not output:
            self.button = "UnLoaded"
        else:
            self.button = "Loaded"

    def picom(self):
        if self.button:
            data = {'button': self.button}
            full_text = self.py3.safe_format(self.format_clicked, data)
        else:
            data = {'button': self.button}
            full_text = self.py3.safe_format(self.format, format)

        return {
            'full_text': full_text,
            'cached_until': self.py3.CACHE_FOREVER
        }

    def on_click(self, event):
        output = os.popen("pgrep -x picom").read()
        if not output:
            self.button = "Loaded"
            os.popen(self.command_start)
        else:
            self.button = "UnLoaded"
            os.popen(self.command_end)

Config

picom {
    format = "<span background='#6C77BB'>   </span><span background='#C4C7C5'> {button} </span>"
    format_clicked = "<span background='#6C77BB'>   </span><span background='#C4C7C5'> {button} </span>"
    command_start = "picom -CGb --experimental-backend --config ~/.config/i3/picom.conf"
    command_end = "killall picom"
}
lasers commented 2 years ago

Untested. Alternative. Slightly different.

process_status picom {
    format = "<span background='#6C77BB'>   </span><span background='#C4C7C5'> {icon} </span>"
    full = True
    cache_timeout = 60

    icon_on = "Loaded"
    icon_off = "UnLoaded"

    on_click 1 = "picom -CGb --experimental-backend --config ~/.config/i3/picom.conf"
    on_click 2 = "killall picom"
}
HeCodes2Much commented 2 years ago

that works like a charm :) cheers

does the 1 and 2 mean different buttons or does that mean depending on the status?

lasers commented 2 years ago
# button numbers
1 = left click
2 = middle click
3 = right click
4 = scroll up
5 = scroll down

https://py3status.readthedocs.io/en/latest/user-guide/configuration/#custom-click-events

EDIT: You also could point a single button to your script too.