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.3.0.tar.gz (6.8 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.3.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hyprland_events-0.3.0.tar.gz
  • Upload date:
  • Size: 6.8 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.3.0.tar.gz
Algorithm Hash digest
SHA256 ba20dc9296d73b927296b641e4091767bc50cd1868ec95a76035ade027f24413
MD5 98e592c534db8e9fad9af66505a970fa
BLAKE2b-256 e2647c636461488d9d0308a25e41ae406144e6d2734b4073204fd9c70c0e3383

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hyprland_events-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38c74abd21cba08d2e134d854bdc46284ea75c17a19bd22bc309d84791ee9496
MD5 3bb93061c82b4b610778333c0e19ed51
BLAKE2b-256 71a65c15455be890909bc4a05d222b19ef52ac18fc45f5fd71b655f4370d69a5

See more details on using hashes here.

Provenance

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