Components API¶
This is the component API reference. Here you will find the nitty-gritty details about Hyprpy component objects.
For a more general overview on how to use components, take a look at the Components guide.
Instance¶
The central Instance
class for interfacing with Hyprland.
This class acts as the root for accessing other components like workspaces, windows, and monitors, and offers capabilities to listen to events and signals emitted by the underlying Hyprland system.
- class Instance(signature: str | None = None)¶
Bases:
object
Represents an active Hyprland instance.
The Instance class is a primary interface for interacting with the Hyprland system. It provides methods for accessing windows, workspaces, and monitors, as well as emitting signals based on events in the Hyprland environment.
- Seealso:
- signature: str¶
Instance signature of the Hyprland instance.
- event_socket: EventSocket¶
The Hyprland event socket for this instance.
- command_socket: CommandSocket¶
The Hyprland command socket for this instance.
- signals: InstanceSignalCollection¶
The
InstanceSignalCollection
for this instance.
- signal_workspace_created: Signal¶
🚫 Deprecated since v0.2.0
This signal has been moved to
createworkspace
and will be removed in future versions of hyprpy.Signal emitted when a new workspace gets created. Sends
created_workspace_id
, theid
of the created workspace, as signal data.
- signal_workspace_destroyed: Signal¶
🚫 Deprecated since v0.2.0
This signal has been moved to
destroyworkspace
and will be removed in future versions of hyprpy.Signal emitted when an existing workspace gets destroyed. Sends
destroyed_workspace_id
, theid
of the destroyed workspace, as signal data.
- signal_active_workspace_changed: Signal¶
🚫 Deprecated since v0.2.0
This signal has been moved to
workspace
and will be removed in future versions of hyprpy.Signal emitted when the focus changes to another workspace. Sends
active_workspace_id
, theid
of the now active workspace, as signal data.
- signal_window_created: Signal¶
🚫 Deprecated since v0.2.0
This signal has been moved to
openwindow
and will be removed in future versions of hyprpy.Signal emitted when a new window gets created. Sends
created_window_address
, theaddress
of the newly created window, as signal data.
- signal_window_destroyed: Signal¶
🚫 Deprecated since v0.2.0
This signal has been moved to
closewindow
and will be removed in future versions of hyprpy.Signal emitted when an existing window gets destroyed. Sends
destroyed_window_address
, theaddress
of the destroyed window, as signal data.
- signal_active_window_changed: Signal¶
🚫 Deprecated since v0.2.0
This signal has been moved to
activewindow
and will be removed in future versions of hyprpy.Signal emitted when the focus changes to another window. Sends
active_window_address
, theaddress
of the now active window, as signal data.
- dispatch(arguments: list[str]) str | None ¶
Runs a generic dispatcher command with the given arguments and returns
None
on success or a string indicating errors.See the Hyprland Wiki for a list of available commands.
Example:
from hyprpy import Hyprland instance = Hyprland() instance.dispatch(["cyclenext", "prev"])
- Parameters:
arguments (list[str]) – A list of strings containing the arguments of the dispatch command.
- Returns:
None if the command succeeded, otherwise a string indicating errors.
- Return type:
str or None
- get_windows() List[Window] ¶
Returns all
Window
s currently managed by the instance.- Returns:
A list containing
Window
objects.
- get_window_by_address(address: str) Window | None ¶
Retrieves the
Window
with the specifiedaddress
.The
address
must be a valid hexadecimal string.- Returns:
The
Window
if it exists, orNone
otherwise.- Raises:
TypeError
ifaddress
is not a string.- Raises:
ValueError
ifaddress
is not a valid hexadecimal string.
- get_active_window() Window ¶
Returns the currently active
Window
.- Returns:
The currently active
Window
.
- get_workspaces() List[Workspace] ¶
Returns all
Workspace
s currently managed by the instance.- Returns:
A list containing
Workspace
s.
- get_workspace_by_id(id: int) Workspace | None ¶
Retrieves the
Workspace
with the specifiedid
.- Returns:
The
Workspace
if it exists, orNone
otherwise.- Raises:
TypeError
ifid
is not an integer.
- get_active_workspace() Workspace ¶
Retrieves the currently active
Workspace
.- Returns:
The currently active
Workspace
.
- get_workspace_by_name(name: int) Workspace | None ¶
Retrieves the
Workspace
with the specifiedname
.- Returns:
The
Workspace
if it exists, orNone
otherwise.- Raises:
TypeError
ifname
is not a string.
- get_monitors() List[Monitor] ¶
Returns all
Monitor
s currently managed by the instance.- Returns:
A list containing
Monitor
s.
- get_monitor_by_id(id: int) Monitor | None ¶
Retrieves the
Monitor
with the specifiedid
.- Returns:
The
Monitor
if it exists, orNone
otherwise.- Raises:
TypeError
ifid
is not an integer.
- get_monitor_by_name(name: str) Monitor | None ¶
Retrieves the
Monitor
with the specifiedname
.- Returns:
The
Monitor
if it exists, orNone
otherwise.- Raises:
TypeError
ifname
is not a string.- Raises:
ValueError
ifname
is an empty string.
- watch() None ¶
Continuosly monitors the
EventSocket
and emits appropriateSignal
s when events are detected.This is a blocking method which runs indefinitely. Signals are continuosly emitted, as soon as Hyprland events are detected.
- Seealso:
Window¶
Window
objects represent individual windows in Hyprland.
- class Window(window_data: dict, instance: Instance)¶
Bases:
object
Represents a window in the Hyprland compositor.
- address: str¶
String representation of a hexadecimal number, unique identifier for the window.
- is_mapped: bool¶
Unknown.
Unknown.
- position_x: int¶
Absolute X-coordinate of the window on the monitor (in pixels).
- position_y: int¶
Absolute Y-coordinate of the window on the monitor (in pixels).
- width: int¶
Width of the window (in pixels).
- height: int¶
Height of the window (in pixels).
- workspace_id: int¶
Numeric ID of the workspace which the window is on.
- workspace_name: str¶
Name of the workspace which the window is on.
- is_floating: bool¶
Whether or not this is a floating window.
- monitor_id: int¶
Numeric ID of the monitor which the window is on.
- wm_class: str¶
Window manager class assigned to this window.
- title: str¶
Current title of the window.
- initial_wm_class: str¶
Window manager class when the window was created.
- initial_title: str¶
Title when the window was created.
- pid: int¶
Process ID of the process the window is assigned to.
- is_xwayland: bool¶
Whether or not the window is using xwayland to be displayed.
- is_pinned: bool¶
Unknown.
- is_fullscreen: int¶
Whether or not the window is in fullscreen mode.
Workspace¶
Workspace
objects represent individual workspaces in Hyprland.
- class Workspace(workspace_data: dict, instance: Instance)¶
Bases:
object
Represents a workspace in Hyprland.
- id: int¶
Numeric ID of the workspace.
- name: str¶
Name assigned to the workspace.
- monitor_name: str¶
Name of the monitor which this workspace is on.
- last_window_address: str¶
Address string of the most recently active window on the workspace.
- last_window_title: str¶
Title of the most recently active window on the workspace.
- window_count: int¶
Number of windows placed in the workspace.
- has_fullscreen: bool¶
True if at least one window in the workspace is in fullscreen mode.
- property last_window_address_as_int: int¶
The integer representation of the workspace’s
last_window_address
property.
Monitor¶
Monitor objects represent monitors in Hyprland.
- class Monitor(monitor_data: str, instance: Instance)¶
Bases:
object
Represents a monitor within Hyprland.
- id: int¶
Numeric ID of the monitor.
- name: str¶
Name of the monitor.
- description: str¶
Manufacturer’s name.
- make: str¶
Model number of the monitor.
- model: str¶
Composite string of make, name and model.
- serial: str¶
Unknown.
- width: int¶
Width of the monitor (in pixels).
- height: int¶
Height of the monitor (in pixels).
- refresh_rate: float¶
Refresh rate of the monitor (in Hz).
- position_x: int¶
Unknown.
- position_y: int¶
Unknown.
- active_workspace_id: int¶
Numeric ID of the workspace currently active on the monitor.
- active_workspace_name: str¶
Assigned name of the workspace currently active on the monitor.
- reserved: List[int]¶
Unknown.
- scale: float¶
Unknown.
- transform: int¶
Unknown.
- is_focused: bool¶
Whether or not the currently focused window is on this monitor.
- uses_dpms: bool¶
Whether or not the monitor uses DPMS.
- vrr: bool¶
Unknown.
Instance Signals¶
The list of signals emitted by hyprpy, which covers all events sent by Hyprland.
- class InstanceSignalCollection¶
Bases:
object
The collection of Hyprland signals emitted by an
Instance
.- activelayout: Signal¶
Emits the following Signal Data when a keyboard’s layout is changed:
Name
Type
Description
keyboard_name
str
Name of the keyboard
layout_name
str
Name of the newly active layout
- activespecial: Signal¶
Emits the following Signal Data when the special workspace on a monitor changes:
Name
Type
Description
workspace_name
str
orNone
name
of the workspace ("special:special"
) if the special workspace was created, andNone
if it was destroyedmonitor_name
str
name
of the monitor
- activespecialv2: Signal¶
Emits the following Signal Data when the special workspace on a monitor changes:
Name
Type
Description
workspace_id
int
orNone
id
of the workspace (-99
) if the special workspace was created, andNone
if it was destroyedworkspace_name
str
orNone
name
of the workspace ("special:special"
) if the special workspace was created, andNone
if it was destroyedmonitor_name
str
name
of the monitor
- activewindow: Signal¶
Emits the following Signal Data when the active window is changed:
Name
Type
Description
window_class
str
The newly active window’s
wm_class
window_title
str
Name of the newly active window’s
title
- activewindowv2: Signal¶
Emits the following Signal Data when the active window is changed:
Name
Type
Description
window_address
str
The newly active Window’s
address
- changefloatingmode: Signal¶
Emits the following Signal Data when a window’s floating state changes:
Name
Type
Description
window_address
str
address
of the windowis_floating
bool
True
if the window is floating, andFalse
otherwise
- closelayer: Signal¶
Emits the following Signal Data when a layerSurface is unmapped:
Name
Type
Description
namespace
str
Unknown.
- closewindow: Signal¶
Emits the following Signal Data when a window is closed:
Name
Type
Description
window_address
str
address
of the closed window
- createworkspace: Signal¶
Emits the following Signal Data when a workspace is created:
Name
Type
Description
workspace_name
str
name
of the created workspace
- createworkspacev2: Signal¶
Emits the following Signal Data when a workspace is created:
Name
Type
Description
workspace_id
int
id
of the created workspaceworkspace_name
str
name
of the created workspace
- destroyworkspace: Signal¶
Emits the following Signal Data when a workspace is destroyed:
Name
Type
Description
workspace_name
str
name
of the destroyed workspace
- destroyworkspacev2: Signal¶
Emits the following Signal Data when a workspace is destroyed:
Name
Type
Description
workspace_id
int
id
of the destroyed workspaceworkspace_name
str
name
of the destroyed workspace
- focusedmon: Signal¶
Emits the following Signal Data when the active monitor changes:
Name
Type
Description
monitor_name
str
name
of the newly active monitorworkspace_name
str
name
of the newly active workspace
- focusedmonv2: Signal¶
Emits the following Signal Data when the active monitor changes:
Name
Type
Description
monitor_name
str
name
of the newly active monitorworkspace_id
int
id
of the workspace which is now active
- fullscreen: Signal¶
Emits the following Signal Data when the fullscreen state of any window changes:
Name
Type
Description
is_fullscreen
bool
True
if fullscreen mode was activated, andFalse
if fullscreen mode was deactivated
- ignoregrouplock: Signal¶
Emits the following Signal Data when
ignoregrouplock
is toggled:Name
Type
Description
ignore_group_lock_enabled
bool
True
ifignoregrouplock
was activated, andFalse
if it was deactivated
- lockgroups: Signal¶
Emits the following Signal Data when
lockgroups
is toggled:Name
Type
Description
lock_groups_enabled
bool
True
iflockgroups
was activated, andFalse
if it was deactivated
- monitoradded: Signal¶
Emits the following Signal Data when a monitor is added:
Name
Type
Description
monitor_name
str
name
of the newly added monitor
- monitoraddedv2: Signal¶
Emits the following Signal Data when a monitor is added:
Name
Type
Description
monitor_id
int
id
of the newly added monitormonitor_name
str
name
of the newly added monitormonitor_description
str
description
of the newly added monitor
- monitorremoved: Signal¶
Emits the following Signal Data when a monitor is removed:
Name
Type
Description
monitor_name
str
name
of the removed monitor
- moveintogroup: Signal¶
Emits the following Signal Data when a window is merged into a group:
Name
Type
Description
window_address
str
address
of the merged window
- moveoutofgroup: Signal¶
Emits the following Signal Data when a window is removed from a group:
Name
Type
Description
window_address
str
address
of the removed window
- movewindow: Signal¶
Emits the following Signal Data when a window is moved to a workspace:
Name
Type
Description
window_address
str
address
of the window which was movedworkspace_name
str
name
of the workspace the window was moved to
- movewindowv2: Signal¶
Emits the following Signal Data when a window is moved to a workspace:
Name
Type
Description
window_address
str
address
of the window which was movedworkspace_name
str
name
of the workspace the window was moved toworkspace_id
int
id
of the workspace the window was moved to
- moveworkspace: Signal¶
Emits the following Signal Data when a workspace is moved to a different monitor:
Name
Type
Description
workspace_name
str
name
of the workspace which was movedmonitor_name
str
name
of the monitor which the workspace was moved to
- moveworkspacev2: Signal¶
Emits the following Signal Data when a workspace is moved to a different monitor:
Name
Type
Description
workspace_id
int
id
of the workspace which was movedworkspace_name
str
name
of the workspace which was movedmonitor_name
str
name
of the monitor which the workspace was moved to
- openlayer: Signal¶
Emits the following Signal Data when a layerSurface is mapped:
Name
Type
Description
namespace
str
Unknown.
- openwindow: Signal¶
Emits the following Signal Data when a window is opened:
Name
Type
Description
window_address
str
address
of the opened windowworkspace_name
str
name
of the workspace on which the window was openedwindow_class
str
The opened window’s
wm_class
window_title
str
Name of the opened window’s
title
- pin: Signal¶
Emits the following Signal Data when a window is pinned or unpinned:
Name
Type
Description
window_address
str
address
of the pinned/unpinned windowis_pinned
bool
True
if the window was pinned, andFalse
if it was unpinned.
- renameworkspace: Signal¶
Emits the following Signal Data when a workspace is renamed:
Name
Type
Description
workspace_id
int
id
of the workspace which was renamednew_name
str
New
name
of the workspace
- screencast: Signal¶
Emits the following Signal Data when the screencopy state of a client changes:
Name
Type
Description
screencast_enabled
bool
True
if the screencast was enabled, andFalse
if it was disabledscreencast_type
str
"MONITOR"
if the screencast was enabled for a monitor, and"WINDOW"
if it was enabled for a window
- submap: Signal¶
Emits the following Signal Data when a keybind submap changes:
Name
Type
Description
submap_name
str
orNone
Name of the new submap, or
None
if the default submap is now active
- togglegroup: Signal¶
Emits the following Signal Data when the togglegroup command is used:
Name
Type
Description
group_is_active
bool
True
if the group was created, andFalse
if it was destroyedwindow_addresses
list[str]
list
ofaddress
es of the windows in the group
- urgent: Signal¶
Emits the following Signal Data when a window requests an urgent state:
Name
Type
Description
window_address
str
address
of the window requesting urgent state
- windowtitle: Signal¶
Emits the following Signal Data when the title of a window changes:
Name
Type
Description
window_address
str
address
of the window whose title changed
- windowtitlev2: Signal¶
Emits the following Signal Data when the title of a window changes:
Name
Type
Description
window_address
str
address
of the window whose title changedwindow_title
str
title
of the window whose title changed
Misc.¶
Common classes, shared among different components.
- exception ParentNotFoundException¶
Bases:
Exception
Raised when a component’s parent could not be found.
This exception may occur due to programming errors or race conditions, for example when a
hyprpy.components.windows.Window
knows the ID of thehyprpy.components.workspaces.Workspace
it is on, but no workspace with that ID exists.