| Crates.io | hyprsession |
| lib.rs | hyprsession |
| version | 0.2.1-1 |
| created_at | 2024-05-21 21:17:21.682799+00 |
| updated_at | 2026-01-04 19:16:33.289809+00 |
| description | Saves hyprland sessions |
| homepage | |
| repository | https://github.com/joshurtree/hyprsession |
| max_upload_size | |
| id | 1247222 |
| size | 161,099 |
Implements session persistence for Hyprland. While the program is running it periodically saves the command, workspace and other properties of running clients found by hyprctl clients. These are then saved to a file formatted as a Hyprland config file which can then be sourced so that the session is restored when Hyprland is restarted.
As root run the command
cargo install --root /usr/local hyprsession
Or install as a user by replacing /usr/local with your home directory.
Hyprsession can be installed via the AUR. By either running your aur package manager of choice or manually by running
git clone https://aur.archlinux.org/hyprsession.git
cd hyprsession
makepkg -i
Add the input to your flake.nix
hyprsession.url = "github:joshurtree/hyprsession"
Then either add the package to your configuration.nix or use ${inputs.hyprsession.packages.${pkgs.system}.hyprsession}/bin/hyprsession in place of hyprsession to run the program.
To automatically run the program in future sessions add the following line to your Hyprland config file (Usually at ~/.config/hypr/hyprland.conf)
exec-once = hyprsession
The same line can be added to your home.nix hyprland configuration if your are using Nix Home Manager.
If you want to save a session that is already running then run
hyprsession save <session-name>
Various options can be used to modify the behavior of Hyprsession.
One of
Name of the session or command
Command to run (see below)
The period of time after loading a session that windows are modified to match virtual counterparts
This sets the interval in seconds between session saves. The default is 60 seconds.
Only simulate loading and clearing of sessions
When loading a session this tell Hyprsession to not clear the current session and restart programs. Instead it moves the existing clients to match the saved session.
Sets the mode the program runs in
Display program help
Display program version
Detecting what command is needed to create any given window in wayland does not have a single uniform solution.
The information within the /proc directory is used to try and find this. If this doesn't yield a command available
via $PATH then the initial_class of the window is checked followed by initial_title.
With applications that come in the form of Flatpaks, Snaps or Electron apps this method does not produce a proper result.
To solve this requires the use of bridge commands. By running hyprctl clients you can find the initial_class of the window. You can then create a bridging command to run the correct command on startup. For example if you use the Firefox flatpak then running
hyprsession command firefox "flatpak run org.mozilla.firefox"
creates a script in the ~/.local/bin directory that runs the correct command.
The original intention for this project was to replicate the experience I had in KDE where most my programs would return after I switched on my computer. This with this update (0.2.1) it seems to be able to do that but the way it is achieved is somewhat hacky. The problem is that the Hyprland dispatcher/event system is oriented around user interaction. This is particularly apparent with application grouping that has dispatchers for adding applications to a group on the left or right. For a user this is easy but the program does know its left from right, so I have to program that logic in as well and any method could be easily broken by edge cases or future Hyprland updates.
The plan going forward is to concentrate on porting the code to a Hyprland plugin. This should give me low level access to client positioning
needed to maintain the session in a cleaner manner and access new features without relying on a dispatcher being created to perform the task.
The intention is the maintain the standalone program and fix any bugs that found. It will also become the cli frontend of the plugin. I am
not planning to add any further features to hyprsession. Instead enhancements such as grouping applications will come via the plugin.
Along side the standard tests you can create a test within a vm using nix by running
cd tests/vm-test
./run-test.sh
This will:
hyprsession savehyprsession loadTest results are saved to tests/test-results/ with detailed comparison data. The programs started can be changed by
editing tests/vm-test/exec.conf
By default the sessions are saved to ~/.local/share/hyprsession. For testing without disrupting your main instance you can set the variable HYPRSESSION_PATH variable in your shell before running the test version of the program.
Thank you to the following people for helping to improve this project