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.

Put the island in a layer-shell overlay on Linux

Salomão Davy1000f44b2969
diff --git a/windows/Cargo.lock b/windows/Cargo.lock
index 98e9044a..6278c752 100644
--- a/windows/Cargo.lock
+++ b/windows/Cargo.lock
@@ -612,6 +612,7 @@ dependencies = [
name = "coucou"
version = "0.1.1"
dependencies = [
+ "gtk",
"keyring",
"libc",
"reqwest 0.12.28",
diff --git a/windows/src-tauri/Cargo.toml b/windows/src-tauri/Cargo.toml
index 3add7e90..f581867d 100644
--- a/windows/src-tauri/Cargo.toml
+++ b/windows/src-tauri/Cargo.toml
@@ -39,3 +39,6 @@ windows = { version = "0.61", features = [
# Secret Service (GNOME Keyring, KWallet) over D-Bus, encrypted in transit.
keyring = { version = "3", features = ["sync-secret-service", "crypto-rust"] }
libc = "0.2"
+# The GTK that Tauri already runs on, to reach its window for layer-shell and
+# the input region. libgtk-layer-shell itself is called directly (platform/linux.rs).
+gtk = "0.18"
diff --git a/windows/src-tauri/src/island.rs b/windows/src-tauri/src/island.rs
index 3d6acbad..7d98f1c2 100644
--- a/windows/src-tauri/src/island.rs
+++ b/windows/src-tauri/src/island.rs
@@ -274,6 +274,36 @@ pub fn spawn_cursor_poll(app: AppHandle, gate: Arc<PollGate>) {
});
}
+/// Re-applies click-through after the window or the island changed shape.
+///
+/// With the cursor poll (Windows) the window takes the mouse again and the next
+/// tick decides from the cursor. Without it (Linux) the input region is set to
+/// the island itself, or to the whole wake strip while collapsed.
+pub fn refresh_click_through(app: &AppHandle, gate: &PollGate) {
+ if platform::CURSOR_POLL {
+ set_ignore_cursor(app, false);
+ gate.forget_ignore_state();
+ return;
+ }
+ let Some(win) = window(app) else { return };
+ let region = if gate.collapsed.load(Ordering::Relaxed) {
+ None
+ } else {
+ let r = *gate.rect.lock().unwrap();
+ if r.w <= 0.0 {
+ // Nothing drawn yet: nothing takes the mouse.
+ Some((0.0, 0.0, 0.0, 0.0))
+ } else {
+ let x0 = (r.x - HIT_MARGIN).max(0.0);
+ let y0 = (r.y - HIT_MARGIN).max(0.0);
+ let x1 = r.x + r.w + HIT_MARGIN;
+ let y1 = r.y + r.h + HIT_MARGIN;
+ Some((x0, y0, x1 - x0, y1 - y0))
+ }
+ };
+ platform::set_input_region(&win, region);
+}
+
pub fn set_ignore_cursor(app: &AppHandle, ignore: bool) {
if let Some(win) = window(app) {
let _ = win.set_ignore_cursor_events(ignore);
diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rs
index 7292852a..0cca0b02 100644
--- a/windows/src-tauri/src/lib.rs
+++ b/windows/src-tauri/src/lib.rs
@@ -39,6 +39,9 @@ pub struct BootInfo {
screen: ScreenInfo,
version: String,
hook_path: String,
+ /// False where the OS has no global cursor (Wayland): the page then reports
+ /// the cursor from its own mouse events.
+ cursor_poll: bool,
}
#[tauri::command]
@@ -52,6 +55,7 @@ fn boot(app: AppHandle, shared: State<Shared>) -> BootInfo {
screen,
version: env!("CARGO_PKG_VERSION").to_string(),
hook_path: settings::hook_exe_path().to_string_lossy().to_string(),
+ cursor_poll: platform::CURSOR_POLL,
}
}
@@ -90,15 +94,18 @@ fn set_collapsed(app: AppHandle, shared: State<Shared>, collapsed: bool) {
shared.gate.collapsed.store(collapsed, Ordering::Relaxed);
island::apply_geometry(&app, &pref, collapsed);
// The wake strip must always take the mouse, and a resize invalidates the flag.
- island::set_ignore_cursor(&app, false);
- shared.gate.forget_ignore_state();
+ island::refresh_click_through(&app, &shared.gate);
shared.gate.set_active(!collapsed);
}
/// The front end pushes the island shape; Rust decides click-through from it.
#[tauri::command]
-fn set_island_rect(shared: State<Shared>, x: f64, y: f64, width: f64, height: f64) {
+fn set_island_rect(app: AppHandle, shared: State<Shared>, x: f64, y: f64, width: f64, height: f64) {
shared.gate.set_rect(island::IslandRect { x, y, w: width, h: height });
+ // Without the cursor poll the input region is the click-through: it follows the island.
+ if !platform::CURSOR_POLL {
+ island::refresh_click_through(&app, &shared.gate);
+ }
}
#[tauri::command]
@@ -396,6 +403,11 @@ pub fn run() {
let _ = win.show();
}
gate.collapsed.store(false, Ordering::Relaxed);
+ // Nothing drawn yet, so nothing takes the mouse until the page
+ // reports the island's shape.
+ if !platform::CURSOR_POLL {
+ island::refresh_click_through(&handle, &gate);
+ }
gate.set_active(true);
island::spawn_cursor_poll(handle.clone(), gate.clone());
diff --git a/windows/src-tauri/src/platform/linux.rs b/windows/src-tauri/src/platform/linux.rs
index ec9b03f0..e8b22087 100644
--- a/windows/src-tauri/src/platform/linux.rs
+++ b/windows/src-tauri/src/platform/linux.rs
@@ -1,13 +1,23 @@
-// Linux: XDG directories for files, xdg-open for links and folders.
+// Linux: XDG directories for files, xdg-open for links and folders, and
+// gtk-layer-shell for the island window.
//
-// The island-window functions are placeholders for now: they do nothing, so the
-// window keeps its Tauri defaults. The real version depends on the session
-// (layer-shell on Wayland compositors that have it, X11 elsewhere).
+// Wayland gives an app no global cursor position and no say over where its
+// window goes, so the island works differently from Windows:
+// * it is a layer-shell surface anchored to the top edge, above everything,
+// on compositors that support it (COSMIC, KDE, wlroots — not GNOME);
+// * click-through is the window's input region, set to the island shape, so
+// the compositor itself sends every other click to whatever is underneath;
+// * the cursor comes from the page's own mouse events, which only fire over
+// the island — Mochi's eyes follow the pointer there, not across the screen.
use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use std::process::Command;
+use std::sync::atomic::{AtomicBool, Ordering};
+use std::sync::Mutex;
+use gtk::glib::translate::ToGlibPtr;
+use gtk::prelude::*;
use tauri::{AppHandle, WebviewWindow};
use super::{home_dir, LocalTime};
@@ -99,8 +109,10 @@ pub fn find_on_path(stem: &str) -> Option<PathBuf> {
// ── Cursor ────────────────────────────────────────────────────────────────────
-/// Not available yet. With no position the poll loop emits nothing and never
-/// turns click-through on, so the island takes every click over its window.
+/// Nothing polls the cursor here: the page reports it over the island, and the
+/// input region decides click-through (see the top of this file).
+pub const CURSOR_POLL: bool = false;
+
pub fn cursor_physical() -> Option<(f64, f64)> {
None
}
@@ -111,9 +123,139 @@ pub fn left_button_down() -> bool {
// ── Island window ─────────────────────────────────────────────────────────────
+/// The few gtk-layer-shell calls we need, straight from the C library.
+mod layer {
+ use gtk::ffi::GtkWindow;
+ use std::os::raw::{c_char, c_int};
+
+ pub const LAYER_OVERLAY: c_int = 3;
+ pub const EDGE_TOP: c_int = 2;
+ pub const KEYBOARD_NONE: c_int = 0;
+ pub const KEYBOARD_ON_DEMAND: c_int = 2;
+
+ #[link(name = "gtk-layer-shell")]
+ extern "C" {
+ pub fn gtk_layer_is_supported() -> c_int;
+ pub fn gtk_layer_init_for_window(window: *mut GtkWindow);
+ pub fn gtk_layer_set_namespace(window: *mut GtkWindow, name_space: *const c_char);
+ pub fn gtk_layer_set_layer(window: *mut GtkWindow, layer: c_int);
+ pub fn gtk_layer_set_anchor(window: *mut GtkWindow, edge: c_int, anchor: c_int);
+ pub fn gtk_layer_set_exclusive_zone(window: *mut GtkWindow, zone: c_int);
+ pub fn gtk_layer_set_keyboard_mode(window: *mut GtkWindow, mode: c_int);
+ }
+}
+
+/// True once the island window is a layer-shell surface.
+static LAYER_SURFACE: AtomicBool = AtomicBool::new(false);
+
+/// The input region last asked for, re-applied whenever the window is mapped:
+/// GTK resets it to the whole window on map. Until the page reports the island
+/// shape it is empty, so nothing takes the mouse.
+type Region = Option<(f64, f64, f64, f64)>;
+static INPUT_REGION: Mutex<Region> = Mutex::new(Some((0.0, 0.0, 0.0, 0.0)));
+
+fn gtk_window_ptr(win: &gtk::ApplicationWindow) -> *mut gtk::ffi::GtkWindow {
+ let w: &gtk::Window = win.upcast_ref();
+ w.to_glib_none().0
+}
+
/// WebKitGTK has no competing drop target to remove.
pub fn unblock_webview_drops(_app: &AppHandle) {}
-pub fn make_non_activating(_win: &WebviewWindow) {}
+/// Turns the island into an overlay surface on the top edge that never takes
+/// the keyboard. Must run before the window is first shown: a layer surface
+/// cannot be made out of a window the compositor already knows.
+///
+/// Without layer-shell (GNOME, X11, or COUCOU_LAYER_SHELL=0) the window stays
+/// an ordinary always-on-top window that refuses focus; where it lands is then
+/// up to the window manager.
+pub fn make_non_activating(win: &WebviewWindow) {
+ let Ok(gw) = win.gtk_window() else { return };
+ // 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;
+ if !wanted || !supported || gw.is_realized() {
+ let why = if !wanted {
+ "COUCOU_LAYER_SHELL=0"
+ } else if supported {
+ "window already shown"
+ } else {
+ "compositor has no layer-shell"
+ };
+ crate::log::line(format!("island is a regular window ({why})"));
+ gw.set_accept_focus(false);
+ return;
+ }
+ // tao gives undecorated Wayland windows an empty titlebar to force
+ // client-side decorations. A layer surface has none, and a client-decorated
+ // GtkWindow recomputes its own input region (shadow margins included) on
+ // every map, over ours.
+ gw.set_titlebar(None::<&gtk::Widget>);
+ let ptr = gtk_window_ptr(&gw);
+ unsafe {
+ layer::gtk_layer_init_for_window(ptr);
+ layer::gtk_layer_set_namespace(ptr, c"coucou".as_ptr());
+ layer::gtk_layer_set_layer(ptr, layer::LAYER_OVERLAY);
+ // Top edge only: the compositor centres the surface horizontally.
+ layer::gtk_layer_set_anchor(ptr, layer::EDGE_TOP, 1);
+ // -1: sit right against the screen edge, over any top panel, the way
+ // the Mac island sits in the notch.
+ layer::gtk_layer_set_exclusive_zone(ptr, -1);
+ layer::gtk_layer_set_keyboard_mode(ptr, layer::KEYBOARD_NONE);
+ }
+ // WebKitGTK in a freshly mapped layer surface never paints its first frame
+ // (seen on COSMIC, and reproduced with a bare GTK window + WebKitGTK, no
+ // Tauri involved): the surface stays empty. Unmapping and mapping it once,
+ // right after the first map, gets it drawing for good.
+ let remapped = std::cell::Cell::new(false);
+ gw.connect_map_event(move |w, _| {
+ apply_input_region(w, *INPUT_REGION.lock().unwrap());
+ if !remapped.replace(true) {
+ let w = w.clone();
+ gtk::glib::idle_add_local_once(move || {
+ w.hide();
+ w.show_all();
+ apply_input_region(&w, *INPUT_REGION.lock().unwrap());
+ });
+ }
+ gtk::glib::Propagation::Proceed
+ });
+ LAYER_SURFACE.store(true, Ordering::Relaxed);
+ crate::log::line("island is a layer-shell overlay");
+}
+
+/// Temporarily allow keyboard focus so a text field inside the island can be
+/// typed in.
+pub fn set_activating(win: &WebviewWindow, activating: bool) {
+ let Ok(gw) = win.gtk_window() else { return };
+ if LAYER_SURFACE.load(Ordering::Relaxed) {
+ let mode = if activating { layer::KEYBOARD_ON_DEMAND } else { layer::KEYBOARD_NONE };
+ unsafe { layer::gtk_layer_set_keyboard_mode(gtk_window_ptr(&gw), mode) };
+ } else {
+ gw.set_accept_focus(activating);
+ }
+}
+
+/// Only this rectangle (window-logical pixels) takes the mouse; `None` means
+/// the whole window does. Everything outside goes to the window underneath.
+pub fn set_input_region(win: &WebviewWindow, rect: Region) {
+ *INPUT_REGION.lock().unwrap() = rect;
+ let Ok(gw) = win.gtk_window() else { return };
+ apply_input_region(&gw, rect);
+}
-pub fn set_activating(_win: &WebviewWindow, _activating: bool) {}
+fn apply_input_region(gw: &impl IsA<gtk::Widget>, rect: Region) {
+ match rect {
+ None => gw.input_shape_combine_region(None),
+ Some((x, y, w, h)) => {
+ let Some(gdk_window) = gw.window() else { return };
+ let region = gtk::cairo::Region::create_rectangle(&gtk::cairo::RectangleInt::new(
+ x.floor() as i32,
+ y.floor() as i32,
+ w.ceil().max(0.0) as i32,
+ h.ceil().max(0.0) as i32,
+ ));
+ gdk_window.input_shape_combine_region(&region, 0, 0);
+ }
+ }
+}
diff --git a/windows/src-tauri/src/platform/windows.rs b/windows/src-tauri/src/platform/windows.rs
index 4273ba18..80f40f14 100644
--- a/windows/src-tauri/src/platform/windows.rs
+++ b/windows/src-tauri/src/platform/windows.rs
@@ -139,6 +139,9 @@ pub fn current_user_sid() -> Option<String> {
// ── Cursor ────────────────────────────────────────────────────────────────────
+/// The 60 Hz poll reads the cursor and flips click-through from it.
+pub const CURSOR_POLL: bool = true;
+
/// Cursor position in physical screen pixels.
pub fn cursor_physical() -> Option<(f64, f64)> {
let mut p = POINT::default();
@@ -219,3 +222,6 @@ pub fn set_activating(win: &WebviewWindow, activating: bool) {
SetWindowLongPtrW(hwnd, GWL_EXSTYLE, want);
}
}
+
+/// Click-through here is the poll's WS_EX_TRANSPARENT toggle, not a region.
+pub fn set_input_region(_win: &WebviewWindow, _rect: Option<(f64, f64, f64, f64)>) {}
diff --git a/windows/src-tauri/tauri.linux.conf.json b/windows/src-tauri/tauri.linux.conf.json
index 6b802601..c2c1c226 100644
--- a/windows/src-tauri/tauri.linux.conf.json
+++ b/windows/src-tauri/tauri.linux.conf.json
@@ -5,5 +5,30 @@
"../target/release/coucou-hook.exe": null,
"../target/release/coucou-hook": "coucou-hook"
}
+ },
+ "app": {
+ "windows": [
+ {
+ "label": "island",
+ "title": "Coucou",
+ "url": "index.html",
+ "width": 240,
+ "height": 6,
+ "resizable": false,
+ "decorations": false,
+ "transparent": true,
+ "shadow": false,
+ "alwaysOnTop": true,
+ "skipTaskbar": true,
+ "focus": false,
+ "visible": false,
+ "center": false,
+ "maximizable": false,
+ "minimizable": false,
+ "closable": false,
+ "dragDropEnabled": true,
+ "additionalBrowserArgs": "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --autoplay-policy=no-user-gesture-required"
+ }
+ ]
}
}
diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.ts
index 2967337e..24aaf55f 100644
--- a/windows/src/core/bridge.ts
+++ b/windows/src/core/bridge.ts
@@ -26,6 +26,8 @@ export interface BootInfo {
screen: { x: number; y: number; width: number; height: number; scale: number };
version: string;
hookPath: string;
+ /** False where the OS has no global cursor (Wayland): see Island.followPageCursor. */
+ cursorPoll: boolean;
}
export const Bridge = {
diff --git a/windows/src/island/island.ts b/windows/src/island/island.ts
index 4a6cc6d1..7fdb6180 100644
--- a/windows/src/island/island.ts
+++ b/windows/src/island/island.ts
@@ -553,9 +553,20 @@ export class Island {
// Outside Tauri (plain browser) drive the cursor from DOM events so the
// island can be inspected with `npm run dev`.
- if (!IS_TAURI) {
- window.addEventListener("mousemove", (e) => this.onCursor(e.clientX, e.clientY));
- }
+ if (!IS_TAURI) this.followPageCursor();
+ }
+
+ /**
+ * Takes the cursor from the page's own mouse events instead of Rust's poll.
+ * Used where the OS has no global cursor position (Wayland): the events only
+ * fire while the pointer is over the island, so leaving the window is
+ * reported as a cursor far away, which is what the poll would have said.
+ */
+ followPageCursor() {
+ window.addEventListener("mousemove", (e) => this.onCursor(e.clientX, e.clientY));
+ window.addEventListener("mouseout", (e) => {
+ if (e.relatedTarget == null) this.onCursor(-10_000, -10_000);
+ });
}
/** Cursor in window-logical coordinates. */
diff --git a/windows/src/main.ts b/windows/src/main.ts
index 5f1c3348..f65d5e75 100644
--- a/windows/src/main.ts
+++ b/windows/src/main.ts
@@ -22,6 +22,7 @@ async function main() {
}
island.applySettings();
State.loadIntegrationTasks();
+ if (boot && !boot.cursorPoll) island.followPageCursor();
await onEvent<{ x: number; y: number }>("cursor", ({ x, y }) => island.onCursor(x, y));