first commit
This commit is contained in:
8
Readme.md
Normal file
8
Readme.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Encoding=UTF-8
|
||||||
|
Version=1.0
|
||||||
|
Type=Application
|
||||||
|
Terminal=false
|
||||||
|
Exec=python3 /opt/xfce4-caffeine/main.py
|
||||||
|
Name=xfce4-caffeine
|
||||||
|
Icon=/opt/xfce4-caffeine/assets/hot_cofee.png
|
||||||
BIN
assets/cold_cofee.png
Executable file
BIN
assets/cold_cofee.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/hot_cofee.png
Executable file
BIN
assets/hot_cofee.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
100
main.py
Normal file
100
main.py
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
from PyQt6.QtGui import QIcon, QAction
|
||||||
|
from PyQt6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
app = QApplication([])
|
||||||
|
app.setQuitOnLastWindowClosed(False)
|
||||||
|
|
||||||
|
# TODO está instalado xdg-utils?
|
||||||
|
# TODO está instalado xwininfo?
|
||||||
|
|
||||||
|
# estado
|
||||||
|
global estado
|
||||||
|
if os.popen("xdg-screensaver status").read() == "enabled\n":
|
||||||
|
estado = True
|
||||||
|
else:
|
||||||
|
estado = False
|
||||||
|
|
||||||
|
# Creating the options
|
||||||
|
menu = QMenu()
|
||||||
|
|
||||||
|
# Menú activar
|
||||||
|
optionActivo = QAction("Activar salvapantallas")
|
||||||
|
optionActivo.triggered.connect(lambda: activar())
|
||||||
|
|
||||||
|
# Menú desactivar
|
||||||
|
optionDesactivo = QAction("Desactivar salvapantallas")
|
||||||
|
optionDesactivo.triggered.connect(lambda: desactivar())
|
||||||
|
|
||||||
|
# Saber si está funcionando y cambiar el icono
|
||||||
|
if estado:
|
||||||
|
icon = QIcon(path + "/assets/cold_cofee.png")
|
||||||
|
menu.addAction(optionDesactivo)
|
||||||
|
else:
|
||||||
|
icon = QIcon(path + "/assets/hot_cofee.png")
|
||||||
|
menu.addAction(optionActivo)
|
||||||
|
|
||||||
|
|
||||||
|
# window id de screensaver
|
||||||
|
global window_id
|
||||||
|
window_id = (
|
||||||
|
subprocess.Popen(
|
||||||
|
'xwininfo -root | grep xwininfo | cut -d" " -f4',
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
shell=True,
|
||||||
|
)
|
||||||
|
.stdout.read()
|
||||||
|
.strip()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# opción desactivar
|
||||||
|
def desactivar():
|
||||||
|
icon = QIcon(path + "/assets/hot_cofee.png")
|
||||||
|
tray.setIcon(icon)
|
||||||
|
menu.removeAction(optionDesactivo)
|
||||||
|
menu.removeAction(quit)
|
||||||
|
menu.addAction(optionActivo)
|
||||||
|
menu.addAction(quit)
|
||||||
|
global window_id
|
||||||
|
suspend_screensaver()
|
||||||
|
|
||||||
|
|
||||||
|
# opción activar
|
||||||
|
def activar():
|
||||||
|
icon = QIcon(path + "/assets/cold_cofee.png")
|
||||||
|
tray.setIcon(icon)
|
||||||
|
menu.removeAction(optionActivo)
|
||||||
|
menu.removeAction(quit)
|
||||||
|
menu.addAction(optionDesactivo)
|
||||||
|
menu.addAction(quit)
|
||||||
|
resume_screensaver()
|
||||||
|
|
||||||
|
|
||||||
|
def suspend_screensaver():
|
||||||
|
# run xdg-screensaver on root window
|
||||||
|
subprocess.Popen("xdg-screensaver suspend " + window_id.decode("utf-8"), shell=True)
|
||||||
|
|
||||||
|
|
||||||
|
def resume_screensaver():
|
||||||
|
subprocess.Popen("xdg-screensaver resume " + window_id.decode("utf-8"), shell=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Adding item on the menu bar
|
||||||
|
tray = QSystemTrayIcon()
|
||||||
|
tray.setIcon(icon)
|
||||||
|
tray.setVisible(True)
|
||||||
|
|
||||||
|
|
||||||
|
# To quit the app
|
||||||
|
quit = QAction("Quit")
|
||||||
|
quit.triggered.connect(app.quit)
|
||||||
|
menu.addAction(quit)
|
||||||
|
|
||||||
|
# Adding options to the System Tray
|
||||||
|
tray.setContextMenu(menu)
|
||||||
|
|
||||||
|
app.exec()
|
||||||
Reference in New Issue
Block a user