Skip to main content

Typed event dispatch layer for Hyprland IPC

Project description

hyprland-events

Typed event dispatch layer for Hyprland IPC. Built on top of hyprland-socket.

Every Hyprland event is parsed into a frozen dataclass with named fields — no more splitting strings on commas.

Installation

pip install hyprland-events

Usage

Blocking event loop

from hyprland_events import EventDispatcher, WorkspaceEvent, MonitorAddedEvent

dispatcher = EventDispatcher()

@dispatcher.on("workspacev2")
def on_workspace(event: WorkspaceEvent):
    print(f"Switched to workspace {event.id} ({event.name})")

@dispatcher.on("monitoraddedv2")
def on_monitor(event: MonitorAddedEvent):
    print(f"Monitor {event.name} connected")

dispatcher.run()  # blocks until the socket closes

on() also works without the decorator syntax:

dispatcher.on("workspacev2", my_handler)

GLib / GTK integration

from gi.repository import GLib
from hyprland_events import EventDispatcher

dispatcher = EventDispatcher()
dispatcher.on("configreloaded", lambda e: print("Config reloaded"))

sock, feed = dispatcher.connect()
GLib.io_add_watch(
    sock.fileno(), GLib.IO_IN,
    lambda *_: feed(sock.recv(4096)) or True,
)

Wildcard handler

dispatcher.on("*", lambda event: print(event))

One-off parsing

from hyprland_events import parse_event

event = parse_event("workspacev2", "3,code")
# WorkspaceEvent(id=3, name='code')

Supported events

Socket name Dataclass Fields
workspacev2 WorkspaceEvent id, name
focusedmonv2 FocusedMonitorEvent monitor, workspace_id
activewindow ActiveWindowEvent wm_class, title
activewindowv2 ActiveWindowV2Event address
fullscreen FullscreenEvent active
monitoraddedv2 MonitorAddedEvent id, name, description
monitorremovedv2 MonitorRemovedEvent id, name, description
createworkspacev2 CreateWorkspaceEvent id, name
destroyworkspacev2 DestroyWorkspaceEvent id, name
moveworkspacev2 MoveWorkspaceEvent id, name, monitor
renameworkspace RenameWorkspaceEvent id, name
activespecialv2 ActiveSpecialEvent id, name, monitor
activelayout ActiveLayoutEvent keyboard, layout
openwindow OpenWindowEvent address, workspace, wm_class, title
closewindow CloseWindowEvent address
movewindowv2 MoveWindowEvent address, workspace_id, workspace_name
openlayer OpenLayerEvent namespace
closelayer CloseLayerEvent namespace
submap SubmapEvent name
changefloatingmode FloatingEvent address, floating
urgent UrgentEvent address
minimized MinimizeEvent address, minimized
screencast ScreencastEvent active, owner
windowtitlev2 WindowTitleEvent address, title
configreloaded ConfigReloadedEvent (none)
pin PinEvent address, pinned
kill KillEvent address
togglegroup ToggleGroupEvent active, addresses
moveintogroup MoveIntoGroupEvent address
moveoutofgroup MoveOutOfGroupEvent address
ignoregrouplock IgnoreGroupLockEvent active
lockgroups LockGroupsEvent locked
bell BellEvent address

Unrecognized events are passed to handlers as the raw hyprland_socket.Event(name, data) object.

For sending commands and querying Hyprland state, see hyprland-socket.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hyprland_events-0.2.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyprland_events-0.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file hyprland_events-0.2.0.tar.gz.

File metadata

  • Download URL: hyprland_events-0.2.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hyprland_events-0.2.0.tar.gz
Algorithm Hash digest
SHA256 57d9f9a0ccc0f65175a7746f731e3893abaf5e3273777ef1ba3f31ae8ccd8038
MD5 f7af1444a77f9c41dcb4b4c8a2a49eb2
BLAKE2b-256 34afe93f17035dee02990a14e1debc5a0ba258a411c621ef55b17c9ad42f0ca9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyprland_events-0.2.0.tar.gz:

Publisher: publish.yml on BlueManCZ/hyprland-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyprland_events-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hyprland_events-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c53bfb1451fabde68369b1f8a3b307ad3b6ef1dcb74be751188e6252a0f3e4f
MD5 f804ea9b083f185e0ab9666a72b5b67b
BLAKE2b-256 dea40640160890dc0a681fa7f3bf22ab1a0426188222da945659da6d2e491c4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyprland_events-0.2.0-py3-none-any.whl:

Publisher: publish.yml on BlueManCZ/hyprland-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page