Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- **niri** *(Linux)* — "Open terminal" now brings the session's window forward on niri, native Wayland windows such as Zed's included (it used to reach only X11 and KDE windows). The README lists niri among the layer-shell compositors and shows the `binds` to put in `config.kdl` for the shortcuts, since niri has no GlobalShortcuts portal

## 0.6.1 — November 19, 2026

- **Mochi no longer weighs down 120 Hz Macs** — on a ProMotion screen Mochi was redrawn 120 times a second, even folded in the notch: 35 to 60 % CPU, and as much again in WindowServer. He is now drawn at 60 fps while the island is open and 30 folded, the mini Mochis at 30, with the same motion on every screen; on a ProMotion Mac he also stops moving twice as fast (#1116, found by @liztim17)
Expand Down
16 changes: 14 additions & 2 deletions windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ It needs `webkit2gtk-4.1`, `gtk-layer-shell` and `libayatana-appindicator`
What changes on Linux:

- **The island** is a gtk-layer-shell overlay anchored to the top edge, over any
top panel, on compositors that support it: COSMIC, KDE Plasma, Hyprland, Sway
top panel, on compositors that support it: COSMIC, KDE Plasma, Hyprland, niri, Sway
and other wlroots compositors. GNOME has no layer-shell and ignores where a
Wayland window asks to go, so there Coucou runs through XWayland as a dock
window: top centre, on every workspace, still there after Super+D.
Expand All @@ -772,7 +772,7 @@ What changes on Linux:
they follow it only while it is over him, and "the cursor is far away" (so
he may fall asleep) means it hasn't been over him for a few seconds.
- **Mochi on the desktop** is a layer-shell surface on the island's display
(KDE Plasma, COSMIC, Hyprland, Sway…), placed with margins and dragged within
(KDE Plasma, COSMIC, Hyprland, niri, Sway…), placed with margins and dragged within
that display; on X11 it is an ordinary always-on-top window that goes
anywhere. **GNOME on Wayland** has no layer-shell and lets no app place its
own window, so there Mochi can't leave the island: dragging him does nothing,
Expand Down Expand Up @@ -808,6 +808,13 @@ What changes on Linux:
Coucou that is already open. The ids are `toggleIsland`, `openChat`,
`goToAlert`, `jumpToTerminal`, `nextPill`, `prevPill`, `muteToggle`,
`desktopToggle` and `wardrobeToggle`.
**niri** has no GlobalShortcuts portal, so its keys go in `~/.config/niri/config.kdl`:
```kdl
binds {
Mod+Space { spawn "coucou" "--shortcut" "openChat"; }
Mod+Shift+Space { spawn "coucou" "--shortcut" "toggleIsland"; }
}
```
- **Keys** live in the Secret Service (GNOME Keyring, KWallet).
- **Spotify** (Settings → Integrations) is read over MPRIS, Spotify's D-Bus
interface on the session bus: the pill shows the track and plays, pauses
Expand Down Expand Up @@ -856,6 +863,11 @@ What changes on Linux:
- **KDE Plasma on Wayland**: a few lines of KWin script, loaded over D-Bus
from `$XDG_RUNTIME_DIR`, activate the window by process ID and are unloaded
right after; Plasma 5 and 6.
- **niri**: `niri msg --json windows` lists every window with its process ID,
native Wayland ones included (Zed, kitty, Alacritty, foot…); the nearest
ancestor's window gets a `niri msg action focus-window`, which scrolls to it
and switches to its workspace. `niri` must be on the `PATH` of Coucou's
session.
- **kitty**, anywhere: its tab is selected too when remote control listens on
a socket (`allow_remote_control` and `listen_on` in kitty.conf).
- **GNOME on Wayland** and other Wayland compositors let no app bring another
Expand Down
101 changes: 91 additions & 10 deletions windows/src-tauri/src/platform/linux_focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,24 @@ fn linked_chain(owners: &[u32], procs: &[Option<Proc>]) -> Vec<(u32, String)> {
enum Method {
KWin,
X11,
Niri,
}

/// Best first. On Plasma's Wayland session KWin sees every window, native or
/// XWayland; elsewhere EWMH is the standard way, with KWin's script as a
/// second try on Plasma's X11 session.
fn methods(session_type: &str, wayland_display: &str, display: &str, desktop: &str) -> Vec<Method> {
/// XWayland, and so does niri through its socket; elsewhere EWMH is the
/// standard way, with KWin's script as a second try on Plasma's X11 session.
fn methods(session_type: &str, wayland_display: &str, display: &str, desktop: &str, niri_socket: &str) -> Vec<Method> {
let wayland = session_type.eq_ignore_ascii_case("wayland") || !wayland_display.trim().is_empty();
let x11 = !display.trim().is_empty();
let kde = desktop.split(':').any(|d| d.eq_ignore_ascii_case("kde"));
let niri = wayland && !niri_socket.trim().is_empty();
let mut out = Vec::new();
if kde && wayland {
out.push(Method::KWin);
}
if niri {
out.push(Method::Niri);
}
if x11 {
out.push(Method::X11);
}
Expand All @@ -144,12 +149,14 @@ pub fn focus_session_window(owners: &[u32], folder: &str) -> bool {
&env("WAYLAND_DISPLAY"),
&env("DISPLAY"),
&env("XDG_CURRENT_DESKTOP"),
&env("NIRI_SOCKET"),
)
.into_iter()
.any(|method| {
let done = match method {
Method::KWin => kwin::activate(&pids, folder),
Method::X11 => x11::activate(&pids, folder),
Method::Niri => niri::activate(&pids, folder),
};
if done {
crate::log::line(format!("open terminal: window raised ({method:?})"));
Expand Down Expand Up @@ -451,6 +458,75 @@ mod kwin {
}
}

// ── niri: niri msg ────────────────────────────────────────────────────────────

mod niri {
use serde_json::Value;

use super::*;

const LIMIT: Duration = Duration::from_secs(2);

/// The id of the window to bring forward out of `niri msg --json windows`:
/// the windows of the nearest ancestor that has any, the one titled after
/// `folder` if there are several. Native Wayland and XWayland windows alike
/// carry their process ID.
pub fn pick(windows: &str, ancestors: &[u32], folder: &str) -> Option<u64> {
let list: Value = serde_json::from_str(windows).ok()?;
let windows: Vec<(u64, u32, String)> = list
.as_array()?
.iter()
.filter_map(|w| {
let id = w.get("id")?.as_u64()?;
let pid = u32::try_from(w.get("pid")?.as_i64()?).ok()?;
let title = w.get("title").and_then(Value::as_str).unwrap_or_default().to_string();
ancestors.contains(&pid).then_some((id, pid, title))
})
.collect();
session_window::choose_window(ancestors, &windows, folder).copied()
}

pub fn activate(ancestors: &[u32], folder: &str) -> bool {
let Ok(out) = Command::new("niri").args(["msg", "--json", "windows"]).stdin(Stdio::null()).stderr(Stdio::null()).output()
else {
return false;
};
let Some(id) = pick(&String::from_utf8_lossy(&out.stdout), ancestors, folder) else {
return false;
};
// Scrolls to the window and switches to its workspace.
run_quietly(Command::new("niri").args(["msg", "action", "focus-window", "--id", &id.to_string()]), LIMIT)
}

#[cfg(test)]
mod tests {
use super::*;

const WINDOWS: &str = r#"[
{"id":11,"title":"notes","app_id":"kitty","pid":900,"workspace_id":1},
{"id":12,"title":"lib.rs — other — Zed","app_id":"dev.zed.Zed","pid":700,"workspace_id":2},
{"id":13,"title":"main.rs — coucou — Zed","app_id":"dev.zed.Zed","pid":700,"workspace_id":2},
{"id":14,"title":"no pid","app_id":"x"},
{"id":-1,"title":"coucou","app_id":"x","pid":600}
]"#;

#[test]
fn the_window_of_the_session_folder_is_picked() {
// claude → zsh → zed (700): the window titled after the folder wins.
assert_eq!(pick(WINDOWS, &[710, 705, 700], "coucou"), Some(13));
// No title names it: the first window of the process.
assert_eq!(pick(WINDOWS, &[700], "elsewhere"), Some(12));
}

#[test]
fn nothing_is_picked_without_an_ancestor_window_or_with_garbage() {
assert_eq!(pick(WINDOWS, &[1234], "coucou"), None);
assert_eq!(pick(WINDOWS, &[600], "coucou"), None);
assert_eq!(pick("not json", &[700], "coucou"), None);
}
}
}

// ── kitty: the session's tab ──────────────────────────────────────────────────

mod kitty {
Expand Down Expand Up @@ -503,16 +579,21 @@ mod tests {
fn the_best_way_comes_first_for_each_desktop() {
use Method::*;
// Plasma on Wayland: KWin sees everything; XWayland as a second try.
assert_eq!(methods("wayland", "wayland-0", ":0", "KDE"), [KWin, X11]);
assert_eq!(methods("", "wayland-0", "", "KDE"), [KWin]);
assert_eq!(methods("wayland", "wayland-0", ":0", "KDE", ""), [KWin, X11]);
assert_eq!(methods("", "wayland-0", "", "KDE", ""), [KWin]);
// Plasma on X11: EWMH, then KWin.
assert_eq!(methods("x11", "", ":0", "KDE"), [X11, KWin]);
assert_eq!(methods("x11", "", ":0", "KDE", ""), [X11, KWin]);
// Any X11 session.
assert_eq!(methods("x11", "", ":0", "XFCE"), [X11]);
assert_eq!(methods("x11", "", ":0", "XFCE", ""), [X11]);
// GNOME on Wayland: only XWayland windows can be reached.
assert_eq!(methods("wayland", "wayland-0", ":0", "ubuntu:GNOME"), [X11]);
assert_eq!(methods("wayland", "wayland-0", "", "GNOME"), []);
assert_eq!(methods("tty", "", "", ""), []);
assert_eq!(methods("wayland", "wayland-0", ":0", "ubuntu:GNOME", ""), [X11]);
assert_eq!(methods("wayland", "wayland-0", "", "GNOME", ""), []);
assert_eq!(methods("tty", "", "", "", ""), []);
// niri sees native Wayland windows (Zed, kitty...) and XWayland ones.
assert_eq!(methods("wayland", "wayland-1", ":0", "niri", "/run/user/1000/niri.sock"), [Niri, X11]);
assert_eq!(methods("wayland", "wayland-1", "", "niri", "/run/user/1000/niri.sock"), [Niri]);
// A stale NIRI_SOCKET outside a Wayland session is not taken.
assert_eq!(methods("x11", "", ":0", "XFCE", "/run/user/1000/niri.sock"), [X11]);
}

#[test]
Expand Down