-
Notifications
You must be signed in to change notification settings - Fork 19
Development
It's easy to write your own plugin by making a python package and then indicating it's name as the plugin name.
Plugins can be loaded with full python module path, eg: "mymodule.pyprlandplugin"
, the loaded module must provide an Extension
class.
Check the interface.py
file to know the base methods, also have a look at the example below.
To get more details when an error is occurring, use pypr --debug <log file path>
, it will also display the log in the console.
Note
To quickly get started, you can directly edit the experimental
built-in plugin.
In order to distribute it, make your own Python package or trigger a pull request.
If you prefer to make a separate package, check the examples's package
The Extension
interface provides a couple of built-in attributes:
-
config
: object exposing the plugin section inpyprland.toml
-
notify
,notify_error
,notify_info
: access to Hyprland's notification system -
hyprctl
,hyprctlJSON
: invoke Hyprland's IPC system
Important
Contact me to get your extension listed on the home page
Instead of killing the existing pypr
, use:
pypr exit
The "hidden" exit
command will exit cleanly, removing the IPC socket, so you can start pypr again without any complication.
Then you can run pypr
in the terminal, getting the logs in real time and in a log file, ^C
will also exit cleanly so you can re-run the command with no hassle:
pypr --debug /tmp/output.log
from .interface import Plugin
class Extension(Plugin):
" My plugin "
async def init(self):
await self.notify("My plugin loaded")
Just add a method called run_<name of your command>
, eg with "togglezoom" command:
zoomed = False
async def run_togglezoom(self, args):
""" this doc string will show in `help` to document `togglezoom`
But this line will not show in the CLI help
"""
if self.zoomed:
await self.hyprctl('misc:cursor_zoom_factor 1', 'keyword')
else:
await self.hyprctl('misc:cursor_zoom_factor 2', 'keyword')
self.zoomed = not self.zoomed
Similar as a command, implement some async def event_<the event you are interested in>
method.
Pypr ensures only one run_
or event_
handler runs at a time, allowing the plugins code to stay simple and avoid the need for concurrency handling.
However, each plugin can run its handlers in parallel.
You'll find a basic external plugin in the examples folder.
It provides one command: pypr dummy
.
Read the plugin code
It's a simple python package. To install it for development without a need to re-install it for testing, you can use pip install -e .
in this folder.
It's ready to be published using poetry publish
, don't forget to update the details in the pyproject.toml
file.
Ensure you added pypr_examples.focus_counter
to your plugins
list:
[pyprland]
plugins = [
"pypr_examples.focus_counter"
]
Optionally you can customize one color:
["pypr_examples.focus_counter"]
color = "FFFF00"
Run:
tox -e doc
pkill pypr
rm /tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.pyprland.sock
You can now run pypr --debug /tmp/pypr.log
, it will also show the logs and print()
in the terminal.
Press Control+C
and repeat the last command to test your newly changed code.