hyprland-wiki/pages/IPC/_index.md

91 lines
1.8 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-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:
`EVENT>>DATA\n` (\\n is a linebreak)
e.g.: `workspace>>2`
## Events list:
### workspace
emitted on workspace change. Is emitted ONLY when a user requests a workspace
change, and is not emitted on mouse movements (see `activemon`)
2022-08-13 19:06:18 +02:00
Data: `WORKSPACENAME`
2022-08-12 20:46:36 +02:00
### focusedmon
emitted on the active monitor being changed.
2022-08-13 19:06:18 +02:00
Data: `MONNAME,WORKSPACENAME`
2022-08-12 20:46:36 +02:00
### activewindow
emitted on the active window being changed.
2022-08-13 19:06:18 +02:00
Data: `WINDOWCLASS,WINDOWTITLE`
2022-08-12 20:46:36 +02:00
### fullscreen
emitted when a fullscreen status of a window changes.
Warning: a fullscreen event is not guaranteed to fire on/off once in succession.
A window might do for example 3 requests to be fullscreen'd, which would result
in 3 fullscreen events.
2022-08-13 19:06:18 +02:00
Data: `0/1` (exit fullscreen / enter fullscreen)
2022-08-12 20:46:36 +02:00
### monitorremoved
emitted when a monitor is removed (disconnected)
2022-08-13 19:06:18 +02:00
Data: `MONITORNAME`
2022-08-12 20:46:36 +02:00
### monitoradded
emitted when a monitor is added (connected)
2022-08-13 19:06:18 +02:00
Data: `MONITORNAME`
2022-08-12 20:46:36 +02:00
### createworkspace and destroyworkspace
emitted when a workspace is created or removed
2022-08-13 19:06:18 +02:00
Data: `WORKSPANCENAME`
2022-08-12 20:46:36 +02:00
## How to use socket2 with bash
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
```