mirror of
https://github.com/danbulant/dots-hyprland
synced 2026-05-24 12:22:09 +00:00
idle inhibitor: use quickshell instead of pythong script
This commit is contained in:
parent
b972d3fabe
commit
4f0522d913
4 changed files with 48 additions and 105 deletions
|
|
@ -62,6 +62,10 @@ Singleton {
|
||||||
property string provider: "yandere"
|
property string provider: "yandere"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property JsonObject idle: JsonObject {
|
||||||
|
property bool inhibit: false
|
||||||
|
}
|
||||||
|
|
||||||
property JsonObject timer: JsonObject {
|
property JsonObject timer: JsonObject {
|
||||||
property JsonObject pomodoro: JsonObject {
|
property JsonObject pomodoro: JsonObject {
|
||||||
property bool running: false
|
property bool running: false
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,16 @@
|
||||||
import qs.modules.common
|
|
||||||
import qs.modules.common.widgets
|
import qs.modules.common.widgets
|
||||||
import qs
|
import qs
|
||||||
import Quickshell.Io
|
import qs.services
|
||||||
import Quickshell
|
|
||||||
|
|
||||||
QuickToggleButton {
|
QuickToggleButton {
|
||||||
id: root
|
id: root
|
||||||
toggled: false
|
toggled: Idle.inhibit
|
||||||
buttonIcon: "coffee"
|
buttonIcon: "coffee"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (toggled) {
|
Idle.toggleInhibit()
|
||||||
root.toggled = false
|
|
||||||
Quickshell.execDetached(["pkill", "wayland-idle"]) // pkill doesn't accept too long names
|
|
||||||
} else {
|
|
||||||
root.toggled = true
|
|
||||||
Quickshell.execDetached([`${Directories.scriptPath}/wayland-idle-inhibitor.py`])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Process {
|
|
||||||
id: fetchActiveState
|
|
||||||
running: true
|
|
||||||
command: ["pidof", "wayland-idle-inhibitor.py"]
|
|
||||||
onExited: (exitCode, exitStatus) => {
|
|
||||||
root.toggled = exitCode === 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
StyledToolTip {
|
StyledToolTip {
|
||||||
content: Translation.tr("Keep system awake")
|
content: Translation.tr("Keep system awake")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
#!/usr/bin/env -S\_/bin/sh\_-xc\_"source\_\$(eval\_echo\_\$ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate&&exec\_python\_-E\_"\$0"\_"\$@""
|
|
||||||
|
|
||||||
# From https://github.com/stwa/wayland-idle-inhibitor
|
|
||||||
# License: WTFPL Version 2
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from signal import SIGINT, SIGTERM, signal
|
|
||||||
from threading import Event
|
|
||||||
import setproctitle
|
|
||||||
|
|
||||||
from pywayland.client.display import Display
|
|
||||||
from pywayland.protocol.idle_inhibit_unstable_v1.zwp_idle_inhibit_manager_v1 import (
|
|
||||||
ZwpIdleInhibitManagerV1,
|
|
||||||
)
|
|
||||||
from pywayland.protocol.wayland.wl_compositor import WlCompositor
|
|
||||||
from pywayland.protocol.wayland.wl_registry import WlRegistryProxy
|
|
||||||
from pywayland.protocol.wayland.wl_surface import WlSurface
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class GlobalRegistry:
|
|
||||||
surface: WlSurface | None = None
|
|
||||||
inhibit_manager: ZwpIdleInhibitManagerV1 | None = None
|
|
||||||
|
|
||||||
|
|
||||||
def handle_registry_global(
|
|
||||||
wl_registry: WlRegistryProxy, id_num: int, iface_name: str, version: int
|
|
||||||
) -> None:
|
|
||||||
global_registry: GlobalRegistry = wl_registry.user_data or GlobalRegistry()
|
|
||||||
|
|
||||||
if iface_name == "wl_compositor":
|
|
||||||
compositor = wl_registry.bind(id_num, WlCompositor, version)
|
|
||||||
global_registry.surface = compositor.create_surface() # type: ignore
|
|
||||||
elif iface_name == "zwp_idle_inhibit_manager_v1":
|
|
||||||
global_registry.inhibit_manager = wl_registry.bind(
|
|
||||||
id_num, ZwpIdleInhibitManagerV1, version
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
done = Event()
|
|
||||||
signal(SIGINT, lambda _, __: done.set())
|
|
||||||
signal(SIGTERM, lambda _, __: done.set())
|
|
||||||
|
|
||||||
global_registry = GlobalRegistry()
|
|
||||||
|
|
||||||
display = Display()
|
|
||||||
display.connect()
|
|
||||||
|
|
||||||
registry = display.get_registry() # type: ignore
|
|
||||||
registry.user_data = global_registry
|
|
||||||
registry.dispatcher["global"] = handle_registry_global
|
|
||||||
|
|
||||||
def shutdown() -> None:
|
|
||||||
display.dispatch()
|
|
||||||
display.roundtrip()
|
|
||||||
display.disconnect()
|
|
||||||
|
|
||||||
display.dispatch()
|
|
||||||
display.roundtrip()
|
|
||||||
|
|
||||||
if global_registry.surface is None or global_registry.inhibit_manager is None:
|
|
||||||
print("Wayland seems not to support idle_inhibit_unstable_v1 protocol.")
|
|
||||||
shutdown()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
inhibitor = global_registry.inhibit_manager.create_inhibitor( # type: ignore
|
|
||||||
global_registry.surface
|
|
||||||
)
|
|
||||||
|
|
||||||
display.dispatch()
|
|
||||||
display.roundtrip()
|
|
||||||
|
|
||||||
print("Inhibiting idle...")
|
|
||||||
done.wait()
|
|
||||||
print("Shutting down...")
|
|
||||||
|
|
||||||
inhibitor.destroy()
|
|
||||||
|
|
||||||
shutdown()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
setproctitle.setproctitle("wayland-idle-inhibitor.py")
|
|
||||||
main()
|
|
||||||
40
.config/quickshell/ii/services/Idle.qml
Normal file
40
.config/quickshell/ii/services/Idle.qml
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import qs
|
||||||
|
import qs.modules.common
|
||||||
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Wayland
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A nice wrapper for date and time strings.
|
||||||
|
*/
|
||||||
|
Singleton {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property alias inhibit: idleInhibitor.enabled
|
||||||
|
inhibit: Persistent.states.idle.inhibit
|
||||||
|
|
||||||
|
function toggleInhibit() {
|
||||||
|
Persistent.states.idle.inhibit = !Persistent.states.idle.inhibit
|
||||||
|
}
|
||||||
|
|
||||||
|
IdleInhibitor {
|
||||||
|
id: idleInhibitor
|
||||||
|
window: PanelWindow { // Inhibitor requires a "visible" surface
|
||||||
|
// Actually not lol
|
||||||
|
implicitWidth: 0
|
||||||
|
implicitHeight: 0
|
||||||
|
color: "transparent"
|
||||||
|
// Just in case...
|
||||||
|
anchors {
|
||||||
|
right: true
|
||||||
|
bottom: true
|
||||||
|
}
|
||||||
|
// Make it not interactable
|
||||||
|
mask: Region {
|
||||||
|
item: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue