#!/usr/bin/env python3
import gi
import subprocess
gi.require_version("Gtk", "3.0")
gi.require_version("AppIndicator3", "0.1")
from gi.repository import Gtk, AppIndicator3

# Comandos a ejecutar
COMMANDS = {
    "previous": ["playerctl", "previous"],
    "play-pause": ["playerctl", "play-pause"],
    "next": ["playerctl", "next"]
}

# Íconos a mostrar (pueden ser nombres de iconos estándar o rutas absolutas a iconos PNG/SVG)
ICONS = {
    "previous": "/home/teraflops/icons/prev.svg",
    "play-pause": "/home/teraflops/icons/play.svg",
    "next": "/home/teraflops/icons/next.svg"
}

def create_indicator(name, icon_path, command):
    indicator = AppIndicator3.Indicator.new(
        name,
        icon_path,
        AppIndicator3.IndicatorCategory.APPLICATION_STATUS
    )
    indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)

    # Truco para clic izquierdo sin menú contextual visible
    menu = Gtk.Menu()

    default_item = Gtk.MenuItem(label="")
    default_item.connect("activate", lambda _: subprocess.run(command))
    default_item.show()
    menu.append(default_item)

    indicator.set_menu(menu)

    # Forzar que clic izquierdo ejecute directamente la acción
    indicator.set_secondary_activate_target(default_item)

if __name__ == "__main__":
    create_indicator("media-prev", ICONS["previous"], COMMANDS["previous"])
    create_indicator("media-play", ICONS["play-pause"], COMMANDS["play-pause"])
    create_indicator("media-next", ICONS["next"], COMMANDS["next"])
    Gtk.main()

