From fac6d2bd7f7e96145e1511d146442fb86941b996 Mon Sep 17 00:00:00 2001 From: nevaforget <> Date: Mon, 31 Aug 2026 12:49:16 +0200 Subject: [PATCH] feat(quickshell): close the window on a middle click of its title Closing goes through the window id rather than niri's focused-window default: the click and the moment niri acts on it are not the same instant, and the focus can move in between. --- defaults/xdg/quickshell/moonarch/Niri.qml | 14 ++++++++++++++ defaults/xdg/quickshell/moonarch/WindowTitle.qml | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/defaults/xdg/quickshell/moonarch/Niri.qml b/defaults/xdg/quickshell/moonarch/Niri.qml index 161c87a..2cddb27 100644 --- a/defaults/xdg/quickshell/moonarch/Niri.qml +++ b/defaults/xdg/quickshell/moonarch/Niri.qml @@ -131,4 +131,18 @@ Singleton { Process { id: focusProc } + + // Close a window by id rather than by focus: the click that asks for this + // and the moment niri acts on it are not the same instant, and the focus + // can move in between. + function closeWindow(id) { + if (id === null || id === undefined) + return; + closeProc.command = ["niri", "msg", "action", "close-window", "--id", String(id)]; + closeProc.running = true; + } + + Process { + id: closeProc + } } diff --git a/defaults/xdg/quickshell/moonarch/WindowTitle.qml b/defaults/xdg/quickshell/moonarch/WindowTitle.qml index 50b23ad..656bd38 100644 --- a/defaults/xdg/quickshell/moonarch/WindowTitle.qml +++ b/defaults/xdg/quickshell/moonarch/WindowTitle.qml @@ -64,6 +64,13 @@ Row { HoverHandler { id: hover } + + // Middle click closes the window the title belongs to. + TapHandler { + acceptedButtons: Qt.MiddleButton + enabled: root.win !== null + onTapped: Niri.closeWindow(root.win.id) + } Tooltip { anchorItem: root shown: hover.hovered