hyprland-wiki/pages/IPC/_index.md

70 lines
2.7 KiB
Markdown
Raw Normal View History

2022-08-12 20:46:36 +02:00
Hyprland exposes 2 UNIX Sockets, for controlling / getting info about Hyprland
via code / bash utilities.
# Hyprland Instance Signature (HIS)
2022-08-12 20:46:36 +02:00
2022-08-13 19:06:18 +02:00
```sh
2022-08-12 20:46:36 +02:00
echo $HYPRLAND_INSTANCE_SIGNATURE
```
# /tmp/hypr/\[HIS\]/.socket.sock
Used for hyprctl-like requests. See the
2022-08-13 19:06:18 +02:00
[Hyprctl page](../Configuring/Using-hyprctl) for
2022-08-12 20:46:36 +02:00
commands.
basically, write `command args`.
# /tmp/hypr/\[HIS\]/.socket2.sock
Used for events. Hyprland will write to each connected client live events like
this:
2022-10-12 17:08:11 +02:00
`EVENT>>DATA\n` (`\n` is a linebreak)
2022-08-12 20:46:36 +02:00
e.g.: `workspace>>2`
# Events list
2022-08-12 20:46:36 +02:00
2022-08-18 17:22:14 +02:00
| name | description | data |
| --- | --- | --- |
| workspace | emitted on workspace change. Is emitted ONLY when a user requests a workspace change, and is not emitted on mouse movements (see `activemon`) | `WORKSPACENAME` |
| focusedmon | emitted on the active monitor being changed. | `MONNAME,WORKSPACENAME` |
| activewindow | emitted on the active window being changed. | `WINDOWCLASS,WINDOWTITLE` |
| fullscreen | emitted when a fullscreen status of a window changes. | `0/1` (exit fullscreen / enter fullscreen) |
| monitorremoved | emitted when a monitor is removed (disconnected) | `MONITORNAME` |
| monitoradded | emitted when a monitor is added (connected) | `MONITORNAME` |
| createworkspace | emitted when a workspace is created | `WORKSPACENAME` |
| destroyworkspace | emitted when a workspace is destroyed | `WORKSPACENAME` |
2022-08-26 16:06:00 +02:00
| moveworkspace | emitted when a workspace is moved to a different monitor | `WORKSPACENAME,MONNAME` |
2022-08-18 17:51:17 +02:00
| activelayout | emitted on a layout change of the active keyboard | `KEYBOARDNAME,LAYOUTNAME` |
2022-08-21 17:23:55 +02:00
| openwindow | emitted when a window is opened | `WINDOWADDRESS`,`WORKSPACENAME`,`WINDOWCLASS`,`WINDOWTITLE` |
| closewindow | emitted when a window is closed | `WINDOWADDRESS` |
| movewindow | emitted when a window is moved to a workspace | `WINDOWADDRESS`,`WORKSPACENAME` |
2022-10-07 23:24:46 +02:00
| openlayer | emitted when a layerSurface is mapped | `NAMESPACE` |
| closelayer | emitted when a layerSurface is unmapped | `NAMESPACE` |
2022-09-05 13:51:44 +02:00
| submap | emitted when a keybind submap changes. Empty means default. |`SUBMAPNAME` |
2022-12-09 19:52:43 +01:00
| changefloatingmode | emitted when a window changes its floating mode. `FLOATING` is either 0 or 1. | `WINDOWADDRESS`,`FLOATING` |
2022-08-18 17:22:14 +02:00
{{< hint type=warning >}}
A fullscreen event is not guaranteed to fire on/off once in succession.
2022-08-12 20:46:36 +02:00
A window might do for example 3 requests to be fullscreen'd, which would result
in 3 fullscreen events.
2022-08-18 17:22:14 +02:00
{{< /hint >}}
2022-08-12 20:46:36 +02:00
# How to use socket2 with bash
2022-08-12 20:46:36 +02:00
example script using socket2 events with bash and `socat`:
2022-08-13 19:06:18 +02:00
```sh
2022-08-12 20:46:36 +02:00
#!/bin/sh
function handle {
if [[ ${1:0:12} == "monitoradded" ]]; then
# do_something
fi
}
socat - UNIX-CONNECT:/tmp/hypr/$(echo $HYPRLAND_INSTANCE_SIGNATURE)/.socket2.sock | while read line; do handle $line; done
```