hyprland-wiki/pages/Plugins/Development/Plugin-Guidelines.md

101 lines
3.2 KiB
Markdown
Raw Normal View History

2023-12-06 23:25:03 +01:00
This page documents the recommended guidelines for making a stable and neat
plugin.
2023-02-27 13:32:56 +01:00
{{< toc >}}
2023-12-06 21:09:54 +01:00
## Making your plugin compatible with hyprpm
2023-12-06 23:25:03 +01:00
In order for your plugin to be installable by `hyprpm`, you need a manifest.
`hyprpm` will parse `hyprload` manifests just fine, but it's recommended to use
the more powerful hyprpm manifest.
2023-12-06 21:12:05 +01:00
2023-12-06 21:09:54 +01:00
Make a file in the root of your repository called `hyprpm.toml`.
### Repository metadata
2023-12-06 23:25:03 +01:00
2023-12-06 21:09:54 +01:00
At the beginning, put some metadata about your plugin:
2023-12-06 23:25:03 +01:00
2023-12-06 21:09:54 +01:00
```toml
[repository]
name = "MyPlugin"
authors = ["Me"]
commit_pins = [
["3bb9c7c5cf4f2ee30bf821501499f2308d616f94", "efee74a7404495dbda70205824d6e9fc923ccdae"],
["d74607e414dcd16911089a6d4b6aeb661c880923", "efee74a7404495dbda70205824d6e9fc923ccdae"]
]
```
2023-12-06 23:25:03 +01:00
`name` and `authors` are required. `commit_pins` are optional. See
[commit pins](#commit-pins) for more info.
2023-12-06 21:09:54 +01:00
### Plugins
2023-12-06 23:25:03 +01:00
2023-12-06 21:09:54 +01:00
For each plugin, make a category like this:
2023-12-06 23:25:03 +01:00
2023-12-06 21:09:54 +01:00
```toml
[plugin-name]
description = "An epic plugin that will change the world!"
authors = ["Me"]
output = "plugin.so"
build = [
"make all"
]
```
2023-12-06 23:25:03 +01:00
2023-12-06 21:09:54 +01:00
`description`, `authors` are optional. `output` and `build` are required.
2023-12-06 23:25:03 +01:00
`build` are the commands that `hyprpm` will run in the root of the repo to build
the plugin. Every command will reset the cwd to the repo root.
2023-12-06 21:09:54 +01:00
`output` is the path to the output `.so` file from the root of the repo.
### Commit pins
2023-12-06 23:25:03 +01:00
Commit pins allow you to manage versioning of your plugin. they are pairs of
`hash,hash`, where the first hash is the Hyprland commit hash, and the second is
your plugin's corresponding commit hash.
For example, in the manifest above, `d74607e414dcd16911089a6d4b6aeb661c880923`
corresponds to Hyprland's `0.33.1` release, which means that if someone is
running `0.33.1`, `hyprpm` will reset your plugin to commit hash
2023-12-06 21:09:54 +01:00
`efee74a7404495dbda70205824d6e9fc923ccdae`.
2023-12-06 23:25:03 +01:00
It's recommended you add a pin for each Hyprland release. If no pin matches,
latest git will be used.
2023-12-06 21:09:54 +01:00
2023-02-27 13:32:56 +01:00
## Formatting
2023-12-06 23:25:03 +01:00
Although Hyprland plugins obviously are not _required_ to follow Hyprland's
formatting, naming conventions, etc. it might be a good idea to keep your code
consistent. See
[`.clang-format`](https://github.com/hyprwm/Hyprland/blob/main/.clang-format) in
the Hyprland repo.
2023-02-27 13:32:56 +01:00
## Usage of the API
2023-12-06 23:25:03 +01:00
It's always advised to use the API entries whenever possible, as they are
guaranteed stability as long as the version matches.
2023-02-27 13:32:56 +01:00
2023-12-06 23:25:03 +01:00
It is, of course, possible to use the internal methods by just including the
proper headers, but it should not be treated as the default way of doing things.
Hyprland's internal methods may be changed, removed or added without any prior
notice. It is worth nothing though that methods that "seem" fundamental, like
e.g. `focusWindow` or `mouseMoveUnified` probably are, and are unlikely to
change their general method of functioning.
2023-02-27 13:32:56 +01:00
## Function Hooks
2023-12-06 23:25:03 +01:00
Function hooks allow your plugin to intercept all calls to a function of your
choice. They are to be treated as a last resort, as they are the easiest thing
to break between updates.
2023-02-27 13:32:56 +01:00
Always prefer using Event Hooks.
## Threads
2023-12-06 23:25:03 +01:00
The Wayland event loop is strictly single-threaded. It is not recommended to
create threads in your code, unless they are fully detached from the Hyprland
process. (e.g. saving a file)