Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Fixes on top of #160, #149, #227, #299

Claude8efad4bdad18
diff --git a/linux/arch/PKGBUILD b/linux/arch/PKGBUILD
index 05b1daf1..f0243247 100644
--- a/linux/arch/PKGBUILD
+++ b/linux/arch/PKGBUILD
@@ -9,7 +9,7 @@ pkgrel=1
pkgdesc="Mochi lives at the top of your screen and keeps an eye on your Claude Code sessions"
arch=('x86_64' 'aarch64')
url="https://github.com/Louis-CFM/coucou"
-license=('MIT')
+license=("MIT" "LicenseRef-coucou-assets")
depends=(
'webkit2gtk-4.1'
'gtk3'
diff --git a/windows/src-tauri/src/island.rs b/windows/src-tauri/src/island.rs
index 0ce036da..7ba6d0eb 100644
--- a/windows/src-tauri/src/island.rs
+++ b/windows/src-tauri/src/island.rs
@@ -134,30 +134,87 @@ pub fn monitor_choices(app: &AppHandle) -> Vec<MonitorChoice> {
monitors
.iter()
.map(|m| {
- let (x, y) = logical_origin(m);
- let scale = m.scale_factor();
- let s = m.size();
- let w = (s.width as f64 / scale).round();
- let h = (s.height as f64 / scale).round();
- let name = m.name().cloned().unwrap_or_else(|| "Display".into());
- MonitorChoice { key: format!("at:{x},{y}"), label: format!("{name} — {w}×{h} at {x},{y}") }
+ let d = describe(m);
+ MonitorChoice {
+ key: d.key(),
+ label: format!("{} — {}×{} at {},{}", d.name, d.w, d.h, d.x, d.y),
+ }
})
.collect()
}
+/// What a display is remembered by: its logical origin, plus its name and
+/// logical size, so it is still found after the layout is rearranged or the
+/// resolution changes (the Mac keeps the display's UUID for the same reason;
+/// Tauri has no stable ID).
+#[derive(Debug, Clone, PartialEq)]
+struct DisplayId {
+ name: String,
+ x: i32,
+ y: i32,
+ w: i32,
+ h: i32,
+}
+
+impl DisplayId {
+ /// `at:<x>,<y>` stays first, so a preference saved before still matches.
+ fn key(&self) -> String {
+ format!("at:{},{}|{}|{}x{}", self.x, self.y, self.name.replace('|', " "), self.w, self.h)
+ }
+}
+
+fn describe(m: &Monitor) -> DisplayId {
+ let (x, y) = logical_origin(m);
+ let scale = m.scale_factor();
+ let s = m.size();
+ DisplayId {
+ name: m.name().cloned().unwrap_or_else(|| "Display".into()),
+ x,
+ y,
+ w: (s.width as f64 / scale).round() as i32,
+ h: (s.height as f64 / scale).round() as i32,
+ }
+}
+
+/// Which display a saved `at:` preference points at, best match first: same
+/// place and name; the same name and size elsewhere (layout rearranged); the
+/// same name alone when unique (resolution changed); the same place. None
+/// means unplugged, and the caller falls back to the primary display.
+fn pick_display(pref: &str, displays: &[DisplayId]) -> Option<usize> {
+ let rest = pref.strip_prefix("at:")?;
+ let mut parts = rest.split('|');
+ let (x, y) = parts.next()?.split_once(',')?;
+ let (x, y) = (x.trim().parse::<i32>().ok()?, y.trim().parse::<i32>().ok()?);
+ let name = parts.next();
+ let size = parts.next().and_then(|s| {
+ let (w, h) = s.split_once('x')?;
+ Some((w.parse::<i32>().ok()?, h.parse::<i32>().ok()?))
+ });
+ let at = |d: &DisplayId| d.x == x && d.y == y;
+ if let Some(name) = name {
+ if let Some(i) = displays.iter().position(|d| at(d) && d.name == name) {
+ return Some(i);
+ }
+ if let Some((w, h)) = size {
+ if let Some(i) = displays.iter().position(|d| d.name == name && d.w == w && d.h == h) {
+ return Some(i);
+ }
+ }
+ let mut same_name = displays.iter().enumerate().filter(|(_, d)| d.name == name);
+ if let (Some((i, _)), None) = (same_name.next(), same_name.next()) {
+ return Some(i);
+ }
+ }
+ displays.iter().position(at)
+}
+
/// The display the island lives on: a chosen one, the primary one, or the one
/// under the cursor.
fn target_monitor(app: &AppHandle, pref: &str) -> Option<Monitor> {
let monitors = app.available_monitors().ok()?;
- if let Some((x, y)) = pref
- .strip_prefix("at:")
- .and_then(|r| r.split_once(','))
- .and_then(|(x, y)| Some((x.trim().parse::<i32>().ok()?, y.trim().parse::<i32>().ok()?)))
- {
- // Unplugged or rearranged since: fall back to the primary display.
- if let Some(m) = monitors.iter().find(|m| logical_origin(m) == (x, y)) {
- return Some(m.clone());
- }
+ let ids: Vec<DisplayId> = monitors.iter().map(describe).collect();
+ if let Some(i) = pick_display(pref, &ids) {
+ return Some(monitors[i].clone());
}
if pref == "cursor" {
if let Some((cx, cy)) = cursor_physical() {
@@ -172,6 +229,48 @@ fn target_monitor(app: &AppHandle, pref: &str) -> Option<Monitor> {
.or_else(|| monitors.into_iter().next())
}
+#[cfg(test)]
+mod display_tests {
+ use super::*;
+
+ fn d(name: &str, x: i32, y: i32, w: i32, h: i32) -> DisplayId {
+ DisplayId { name: name.into(), x, y, w, h }
+ }
+
+ #[test]
+ fn a_display_is_found_again_after_changes() {
+ let dell = d("DELL U2720Q", 1920, 0, 2560, 1440);
+ let lap = d("eDP-1", 0, 0, 1920, 1200);
+ let key = dell.key();
+ assert_eq!(pick_display(&key, &[lap.clone(), dell.clone()]), Some(1));
+ // Rearranged: the Dell moved to the left of the laptop.
+ let moved = [d("eDP-1", 2560, 0, 1920, 1200), d("DELL U2720Q", 0, 0, 2560, 1440)];
+ assert_eq!(pick_display(&key, &moved), Some(1));
+ // Resolution changed, still the only Dell.
+ let rescaled = [lap.clone(), d("DELL U2720Q", 1920, 0, 1920, 1080)];
+ assert_eq!(pick_display(&key, &rescaled), Some(1));
+ // Unplugged: nothing, so the caller falls back to the primary display.
+ assert_eq!(pick_display(&key, &[lap.clone()]), None);
+ }
+
+ #[test]
+ fn two_identical_monitors_are_told_apart_by_place() {
+ let a = d("LG 27UL500", 0, 0, 1920, 1080);
+ let b = d("LG 27UL500", 1920, 0, 1920, 1080);
+ assert_eq!(pick_display(&b.key(), &[a.clone(), b.clone()]), Some(1));
+ assert_eq!(pick_display(&a.key(), &[a, b]), Some(0));
+ }
+
+ #[test]
+ fn preferences_saved_before_still_match() {
+ let lap = d("eDP-1", 0, 0, 1920, 1200);
+ let ext = d("HDMI-1", 1920, 0, 1920, 1080);
+ assert_eq!(pick_display("at:1920,0", &[lap.clone(), ext.clone()]), Some(1));
+ assert_eq!(pick_display("primary", &[lap, ext]), None);
+ assert_eq!(pick_display("at:nonsense", &[]), None);
+ }
+}
+
pub fn screen_info(app: &AppHandle, pref: &str) -> ScreenInfo {
match target_monitor(app, pref) {
Some(m) => {
diff --git a/windows/src-tauri/src/platform/linux.rs b/windows/src-tauri/src/platform/linux.rs
index 53543715..8253961d 100644
--- a/windows/src-tauri/src/platform/linux.rs
+++ b/windows/src-tauri/src/platform/linux.rs
@@ -61,6 +61,7 @@ pub fn local_dir() -> PathBuf {
/// plugin paths that vanish once Coucou quits. Give ours its own file.
pub fn prepare_environment() {
prefer_x11_on_gnome();
+ follow_gnome_text_scaling();
if std::env::var_os("APPIMAGE").is_none() || std::env::var_os("GST_REGISTRY").is_some() {
return;
}
@@ -77,15 +78,57 @@ pub fn prepare_environment() {
/// pass theirs down to every child. COUCOU_X11=0 keeps the Wayland window.
fn prefer_x11_on_gnome() {
let env = |k: &str| std::env::var(k).unwrap_or_default();
- if should_prefer_x11(&env("XDG_SESSION_TYPE"), &env("XDG_CURRENT_DESKTOP"), &env("COUCOU_X11")) {
+ if should_prefer_x11(
+ &env("XDG_SESSION_TYPE"),
+ &env("XDG_CURRENT_DESKTOP"),
+ &env("COUCOU_X11"),
+ &env("DISPLAY"),
+ ) {
std::env::set_var("GDK_BACKEND", "x11");
}
}
-fn should_prefer_x11(session: &str, desktop: &str, opt: &str) -> bool {
+/// Only with XWayland actually there (`DISPLAY` set): forcing x11 without it
+/// would leave GTK with no display at all.
+fn should_prefer_x11(session: &str, desktop: &str, opt: &str, display: &str) -> bool {
session.eq_ignore_ascii_case("wayland")
&& desktop.split(':').any(|d| d.eq_ignore_ascii_case("gnome"))
&& opt != "0"
+ && !display.trim().is_empty()
+}
+
+fn is_gnome(desktop: &str) -> bool {
+ desktop.split(':').any(|d| d.eq_ignore_ascii_case("gnome"))
+}
+
+/// GNOME's "Large text" (text-scaling-factor > 1) makes WebKitGTK draw every
+/// font larger inside a window sized in fixed pixels, so the island's content
+/// was cut off (#122). The island's layout is its own, so it asks GDK to undo
+/// that factor for this process only. An explicit GDK_DPI_SCALE always wins.
+fn follow_gnome_text_scaling() {
+ if std::env::var_os("GDK_DPI_SCALE").is_some()
+ || !is_gnome(&std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default())
+ {
+ return;
+ }
+ let Ok(out) = Command::new("gsettings")
+ .args(["get", "org.gnome.desktop.interface", "text-scaling-factor"])
+ .output()
+ else {
+ return;
+ };
+ if let Some(scale) = dpi_scale_for(&String::from_utf8_lossy(&out.stdout)) {
+ std::env::set_var("GDK_DPI_SCALE", scale);
+ }
+}
+
+/// `"1.25\n"` → `Some("0.8")`; `None` for 1.0 or anything unreadable.
+fn dpi_scale_for(gsettings_output: &str) -> Option<String> {
+ let factor: f64 = gsettings_output.trim().parse().ok()?;
+ if !(0.5..=3.0).contains(&factor) || (factor - 1.0).abs() < 0.01 {
+ return None;
+ }
+ Some(format!("{:.4}", 1.0 / factor).trim_end_matches('0').trim_end_matches('.').to_string())
}
pub fn local_time() -> LocalTime {
@@ -230,6 +273,10 @@ pub fn unblock_webview_drops(_app: &AppHandle) {}
/// up to the window manager.
pub fn make_non_activating(win: &WebviewWindow) {
let Ok(gw) = win.gtk_window() else { return };
+ // The pointer watch reports the pointer leaving on every kind of window:
+ // a regular one (GNOME, X11) misses `mouseout` just as a layer surface does.
+ ISLAND_GTK.with(|cell| *cell.borrow_mut() = Some(gw.clone()));
+ watch_pointer_leave(win);
// COUCOU_LAYER_SHELL=0 is the way out on a compositor where it misbehaves.
let wanted = std::env::var("COUCOU_LAYER_SHELL").map(|v| v != "0").unwrap_or(true);
let supported = unsafe { layer::gtk_layer_is_supported() } != 0;
@@ -291,8 +338,6 @@ pub fn make_non_activating(win: &WebviewWindow) {
}
gtk::glib::Propagation::Proceed
});
- ISLAND_GTK.with(|cell| *cell.borrow_mut() = Some(gw.clone()));
- watch_pointer_leave(win);
LAYER_SURFACE.store(true, Ordering::Relaxed);
crate::log::line("island is a layer-shell overlay");
}
@@ -465,10 +510,22 @@ mod tests {
#[test]
fn x11_is_only_preferred_on_gnome_wayland_unless_opted_out() {
- assert!(should_prefer_x11("wayland", "ubuntu:GNOME", ""));
- assert!(!should_prefer_x11("x11", "ubuntu:GNOME", ""));
- assert!(!should_prefer_x11("wayland", "KDE", ""));
- assert!(!should_prefer_x11("wayland", "GNOME", "0"));
+ assert!(should_prefer_x11("wayland", "ubuntu:GNOME", "", ":0"));
+ assert!(!should_prefer_x11("x11", "ubuntu:GNOME", "", ":0"));
+ assert!(!should_prefer_x11("wayland", "KDE", "", ":0"));
+ assert!(!should_prefer_x11("wayland", "GNOME", "0", ":0"));
+ // No XWayland: keep the Wayland window rather than no display at all.
+ assert!(!should_prefer_x11("wayland", "GNOME", "", ""));
+ }
+
+ #[test]
+ fn text_scaling_is_undone_for_the_island() {
+ assert_eq!(dpi_scale_for("1.25\n").as_deref(), Some("0.8"));
+ assert_eq!(dpi_scale_for("1.5").as_deref(), Some("0.6667"));
+ assert_eq!(dpi_scale_for("1.0").as_deref(), None);
+ assert_eq!(dpi_scale_for("").as_deref(), None);
+ assert_eq!(dpi_scale_for("nonsense").as_deref(), None);
+ assert_eq!(dpi_scale_for("40").as_deref(), None);
}
#[test]
diff --git a/windows/src/settings/main.ts b/windows/src/settings/main.ts
index df9a881f..ccc1b77f 100644
--- a/windows/src/settings/main.ts
+++ b/windows/src/settings/main.ts
@@ -394,8 +394,17 @@ function generalSection(): HTMLElement {
screen.value = settings.screen;
void Bridge.listMonitors().then((list) => {
for (const m of list ?? []) screen.append(h("option", { value: m.key, text: m.label }));
- // Set again now the option exists; a display that is gone shows as the main one.
- screen.value = settings.screen;
+ // Set again now the option exists. A display saved under an older key (moved,
+ // resized, or saved before names were kept) is shown by its place or its
+ // name; one that is gone shows as the main one.
+ const saved = settings.screen;
+ const [place, name] = saved.split("|");
+ const keys = (list ?? []).map((m) => m.key);
+ screen.value =
+ keys.find((k) => k === saved) ??
+ (saved.startsWith("at:") ? keys.find((k) => k.split("|")[0] === place) : undefined) ??
+ (name ? keys.find((k) => k.split("|")[1] === name) : undefined) ??
+ saved;
if (!screen.value) screen.value = "primary";
});
screen.addEventListener("change", () => {