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
minimize 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.

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.1.0.tar.gz (13.7 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.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hyprland_events-0.1.0.tar.gz
  • Upload date:
  • Size: 13.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 cf088417343c86290c2618a760d7934762e4ed917aad5a1163971376cbcd1bc0
MD5 2bd85a57a4f6bc596b4efce02c2e10a2
BLAKE2b-256 321bfbbfcb908b7f4b9dd7bbf92f153deb5bfe5d58dacda51342d36f337042bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyprland_events-0.1.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.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hyprland_events-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62dc3d283eae07ce506a7ff41615724a393775b6e54479680eff2dead167c7e6
MD5 c37a8099cd1db816e8dec687a92efda7
BLAKE2b-256 0c1c0f4f6be748b3fa8f2c697b3861109a009ef69b8b232d30143117427ed4c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyprland_events-0.1.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