MCPcopy Index your code
hub / github.com/MTeaHead/niri-session-manager

github.com/MTeaHead/niri-session-manager @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
20 symbols 39 edges 1 files 12 documented · 60%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Niri Session Manager

A session manager for the Niri Wayland compositor that automatically saves and restores your window layout.

Features

  • Periodic session saving with configurable interval
  • Automatic session restoration on startup
  • Backup management with configurable retention
  • Graceful handling of window spawn failures
  • Configurable retry logic for session restoration
  • Custom app launch command mapping via TOML configuration

Usage

The program can be run with various command-line options:

niri-session-manager [OPTIONS]

Options

--save-interval <MINUTES>     How often to save the session (default: 15)
--max-backup-count <COUNT>    Number of backup files to keep (default: 5)
--spawn-timeout <SECONDS>     How long to wait for windows to spawn (default: 5)
--retry-attempts <COUNT>      Number of restore attempts (default: 3)
--retry-delay <SECONDS>       Delay between retry attempts (default: 2)

Configuration

The program supports mapping app IDs to custom launch commands via a TOML configuration file. This is useful for applications where the app ID doesn't match the executable name, or when special launch arguments are needed.

Configuration file location: $XDG_CONFIG_HOME/niri-session-manager/config.toml

Example configuration:

# Niri Session Manager Configuration

# Apps that should only have one instance
[single_instance_apps] 
apps = [
    "firefox",
    "zen"
]

# Applications to skip during startup
[skip_apps]
apps = [
    "discord",
    "slack"
]

#Application remapping
[app_mappings]

# flatpak remapping
"vesktop" = ["flatpak", "run", "dev.vencord.Vesktop"]
"discord" = ["flatpak", "run", "com.discordapp.Discord"]
"slack" = ["flatpak", "run", "com.slack.Slack"]
"obs" = ["flatpak", "run", "com.obsproject.Studio"]

# Simple command remapping
"com.mitchellh.ghostty" = ["ghostty"]
"org.wezfurlong.wezterm" = ["wezterm"]

# Commands with arguments
"firefox-custom" = ["firefox", "--profile", "default-release"]

If no configuration file exists, one will be created with example mappings.

Installation

Using Nix Flakes

{
  description = "Your NixOS configuration";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    niri-session-manager.url = "github:MTeaHead/niri-session-manager";
  };
  outputs = { self, nixpkgs, niri-session-manager, ... }: {
    nixosConfigurations = {
      yourHost = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          # This is not a complete NixOS configuration; reference your normal configuration here.
          # Import the module
          niri-session-manager.nixosModules.niri-session-manager

          ({
            # Enable the service
            services.niri-session-manager.enable = true;
            # Optional: Configure the service
            services.niri-session-manager.settings = {
              save-interval = 30;  # Save every 30 minutes
              max-backup-count = 3;  # Keep 3 most recent backups
            };
          })
        ];
      };
    };
  };
}

Storage

Session data and backups are stored in: - Session file: $XDG_DATA_HOME/niri-session-manager/session.json - Backups: $XDG_DATA_HOME/niri-session-manager/session-{timestamp}.bak - Configuration: $XDG_CONFIG_HOME/niri-session-manager/config.toml

TODO

  • Use PID to fetch the actual process command

Future (when IPC supports it)

  • Grab window size and further details for better placement when restoring windows

Core symbols most depended-on inside this repo

log
called by 14
src/main.rs
get_niri_windows
called by 3
src/main.rs
save_session
called by 2
src/main.rs
get_session_file_path
called by 1
src/main.rs
restore_session
called by 1
src/main.rs
load_app_config
called by 1
src/main.rs
restore_session_internal
called by 1
src/main.rs
handle_shutdown_signals
called by 1
src/main.rs

Shape

Function 14
Class 5
Method 1

Languages

Rust100%

Modules by API surface

src/main.rs20 symbols

For agents

$ claude mcp add niri-session-manager \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact