11 releases

new 0.2.0 Dec 26, 2025
0.1.6 Nov 27, 2025
0.1.5 Sep 14, 2025
0.1.4 Aug 23, 2025
0.1.3 May 30, 2024

#13 in #session

GPL-3.0 license

46KB
672 lines

Hyprsession

Overview

Implements session persistance for Hyprland. While the program is running it periodicly 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.

Buy Me A Coffee

Installation

Manual

As root run the command

cargo install --root /usr/local hyprsession

Or install as a user by replacing /usr/local with your home directory.

Arch Linux

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

NixOS

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.

Usage

To automaticly 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-only &

or

hyprsession save-and-exit

Options

Various options can be used to modify the behavior of Hyprsession.

One of

  • default - Loads the session at startup the saves the current session at regular intervals.
  • load - Load the session given by name (clears current session first)
  • save - Save the current session
  • clear - Clear the current session (removes all windows)
  • list - List all available sessions
  • delete - Delete a session
  • command - Create a command to deal with edge cases (see below)

Name of the session or command

Command to run (see below)

--load-time n

The period of time after loading a session that windows are modified to match virtual counterparts

--save-interval n

This sets the interval in seconds between session saves. The default is 60 seconds.

--session-path

This allows the user to save the session config in an alternative directory, by default its ~/.local/share/hyprsession.

--simulate

Only simulate loading and clearing of sessions

--mode

Sets the mode the program runs in

  • Default - Loads the session at startup the saves the current session at regular intervals.
  • SaveOnly - As above but skips loading the session
  • LoadAndExit - Load the saved session then immediatly exit
  • SaveAndExit - Save the current session then exit

Command detection and fake commands

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 fake commands. An example would be if you use the Firefox flatpak then runing

hyprsession command firefox "flatpak run org.mozilla.firefox"

This creates a script in the ~/.local/bin directory that runs the correct command.

Change log

0.1.1

  • Changed --session-path option to point at base directory of session file

0.1.2

  • Fixed bug which would crash program if no session file existed

0.1.3

  • Fix fatal bug on Hyprland 0.4 that crashed the program while saving the session

0.1.4

  • Changed fullscreen dispatcher to use fullscreenmode and fixed FullscreenMode type issue (#2)
  • Updated to latest alpha version of hyprland crate. Fixes panic on fetching clients (#1)

0.1.5

  • Skip saving clients with duplicate pids (i.e. generated by the same application)
  • Add option to retain clients with duplicate pids

0.1.6

  • Handle special workspaces properly
  • Handle wrapped programs in Nixos

0.2.0

  • Breaking change: Remove the need to use '--mode' to specify what mode to launch the program in
  • Introduce named sessions
  • Improve method of finding originating command for clients
  • Track client creation to try and better place them
  • Introduce 'fake command' functionality to deal with programs complicated launch patterns (flatpak, snap etc.)
  • Refactor code to allow potential future use as either standalone or as a client

Development

Running Tests

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:

  1. Build a NixOS VM with Hyprland and hyprsession
  2. Start test applications (Firefox, terminal, calculator, etc.)
  3. Save a session with hyprsession save
  4. Clear the workspace and restore with hyprsession load
  5. Compare before/after states and report results

Test results are saved to tests/test-results/ with detailed comparison data. The programs started can be changed by editing tests/vm-test/exec.conf

Thanks

Thank you to the following people for helping to improve this project

  • Tie C (ticia)
  • Isaac Hesslegrave (HeadedBranch)
  • Hornet (fsilly)

Dependencies

~7–20MB
~207K SLoC