Skip to content

NiriService does not update status of previously focused window when opening a new window. #451

@KanishakVaidya

Description

@KanishakVaidya

System Information

Ignis 0.5+g57017f8.d20250917
Current desktop: niri

os-release:
ANSI_COLOR="0;38;2;126;186;228"
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
BUILD_ID="25.05.20250920.b2a3852"
CPE_NAME="cpe:/o:nixos:nixos:25.05"
DEFAULT_HOSTNAME=nixos
DOCUMENTATION_URL="https://nixos.org/learn.html"
HOME_URL="https://nixos.org/"
ID=nixos
ID_LIKE=""
IMAGE_ID=""
IMAGE_VERSION=""
LOGO="nix-snowflake"
NAME=NixOS
PRETTY_NAME="NixOS 25.05 (Warbler)"
SUPPORT_END="2025-12-31"
SUPPORT_URL="https://nixos.org/community.html"
VARIANT=""
VARIANT_ID=""
VENDOR_NAME=NixOS
VENDOR_URL="https://nixos.org/"
VERSION="25.05 (Warbler)"
VERSION_CODENAME=warbler
VERSION_ID="25.05"

Description

When a new window is spawned (and automatically focused), the new as well as the old window is tagged as focused window by NiriService.

Let's say I am currently focused on a window with window.id == 1, and I spawn a new window with window.id == 2.

Then ignis.services.niri.NiriService does not reset the is_focused property of the window with window.id == 1. Leaving window.is_focused == True for both window 1 and window 2.

In short, ignis now thinks that more than one windows are in focus simultaneously.

How to reproduce

  1. Download this config.py
  2. Run ignis init -c /path/to/above/config.py under niri.
  3. Monitor the terminal output, you are watching a list of ids of windows for which window.is_focused == True
  4. Create a new window.
  5. Now, you can see in the terminal output, the list contains two window ids.

Additional Information

I looked into the source code and here is my RCA:

On creation of new window, Niri IPC generates a WindowOpenedOrChanged signal, and after receiving this event ignis.services.niri.NiriService calls self.__update_window method (source).

But Niri IPC does not generate WindowFocusChanged event (source) on spawning of new window. This means ignis.services.niri.NiriService does not trigger self.__update_window_focus method, as it only triggers on WindowFocusChanged event.

Proposed fix: inside this if condition, in self.__update_window method add just one more line

        if window.is_focused:
            self.__update_window_focus(window_data)  # <-- This is the new line
            self._active_window.sync(window_data)

So basically, just trigger an update to window focus, on WindowOpenedOrChanged.

I might create an PR with this change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions