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.

Merge #227: Linux: pin the island to its display on layer-shell (Hyprland multi-monitor), display picker, click guard

Claude8761b3661dfd
diff --cc windows/src-tauri/src/platform/linux.rs
index b1d6184e,eeab9736..53543715
--- a/windows/src-tauri/src/platform/linux.rs
+++ b/windows/src-tauri/src/platform/linux.rs
@@@ -296,78 -264,30 +297,102 @@@ pub fn make_non_activating(win: &Webvie
crate::log::line("island is a layer-shell overlay");
}
+thread_local! {
+ /// The island's GTK window, for the pointer watch (GTK main thread only).
+ static ISLAND_GTK: std::cell::RefCell<Option<gtk::ApplicationWindow>> =
+ const { std::cell::RefCell::new(None) };
+}
+
+/// Reports the pointer leaving the island, which the page cannot see by itself.
+///
+/// On a layer surface WebKitGTK does not send `mouseout` when the pointer leaves
+/// for good, and GTK's leave-notify fires spuriously while the pointer is still
+/// over the island (each followed by a re-enter), so neither tells "really
+/// gone". GDK's pointer focus does: it follows the compositor's wl_pointer
+/// enter/leave. It is read every 100 ms while the island is shown; both edges go
+/// to the page as `pointer-inside`, and leaving also emits the far-away cursor
+/// the page uses. While the island is hidden the timer is removed altogether
+/// (set_pointer_watch), so a hidden island costs nothing.
+static POINTER_WIN: std::sync::OnceLock<WebviewWindow> = std::sync::OnceLock::new();
+static WATCH_WANTED: AtomicBool = AtomicBool::new(true);
+static WATCH_RUNNING: AtomicBool = AtomicBool::new(false);
+
+fn watch_pointer_leave(win: &WebviewWindow) {
+ let _ = POINTER_WIN.set(win.clone());
+ start_pointer_watch();
+}
+
+/// Starts or parks the pointer watch. Called with the island's collapsed state;
+/// safe from any thread (the timer itself lives on the GTK main loop).
+pub fn set_pointer_watch(active: bool) {
+ WATCH_WANTED.store(active, Ordering::Relaxed);
+ if active {
+ gtk::glib::MainContext::default().invoke(start_pointer_watch);
+ }
+}
+
+/// Main thread only.
+fn start_pointer_watch() {
+ if !WATCH_WANTED.load(Ordering::Relaxed) || WATCH_RUNNING.swap(true, Ordering::Relaxed) {
+ return;
+ }
+ use tauri::Emitter;
+ let Some(win) = POINTER_WIN.get().cloned() else {
+ WATCH_RUNNING.store(false, Ordering::Relaxed);
+ return;
+ };
+ let inside = std::cell::Cell::new(false);
+ gtk::glib::timeout_add_local(std::time::Duration::from_millis(100), move || {
+ if !WATCH_WANTED.load(Ordering::Relaxed) {
+ WATCH_RUNNING.store(false, Ordering::Relaxed);
+ return gtk::glib::ControlFlow::Break;
+ }
+ let now_inside = ISLAND_GTK
+ .with(|cell| {
+ let gw = cell.borrow().clone()?;
+ let ours = gw.window()?;
+ let pointer = gtk::gdk::Display::default()?.default_seat()?.pointer()?;
+ let (under, _, _) = pointer.window_at_position();
+ Some(under?.toplevel() == ours.toplevel())
+ })
+ .unwrap_or(false);
+ if inside.replace(now_inside) != now_inside {
+ // The page gates its own (late, sometimes stale) mouse events on
+ // this state, so a mousemove queued before the pointer left cannot
+ // pull the island back to "inside".
+ let _ = win.emit("pointer-inside", now_inside);
+ if !now_inside {
+ let _ = win.emit("cursor", crate::island::CursorPayload { x: -10_000.0, y: -10_000.0 });
+ }
+ }
+ gtk::glib::ControlFlow::Continue
+ });
+}
+
+ /// Puts the layer surface on the display whose logical origin is (`x`, `y`).
+ ///
+ /// A layer surface ignores `set_position`: without an explicit output the
+ /// compositor maps it on whichever display has focus at that moment, so on a
+ /// multi-monitor Hyprland or Sway desktop the island wandered from one screen
+ /// to the other every time it was remapped. A no-op for a regular window, which
+ /// `set_position` already places.
+ pub fn pin_to_monitor(win: &WebviewWindow, x: i32, y: i32) {
+ if !LAYER_SURFACE.load(Ordering::Relaxed) {
+ return;
+ }
+ let Ok(gw) = win.gtk_window() else { return };
+ let display = gw.display();
+ let monitor = (0..display.n_monitors())
+ .filter_map(|i| display.monitor(i))
+ .find(|m| {
+ let g = m.geometry();
+ g.x() == x && g.y() == y
+ });
+ let Some(monitor) = monitor else { return };
+ let mon_ptr: *mut gtk::gdk::ffi::GdkMonitor = monitor.to_glib_none().0;
+ unsafe { layer::gtk_layer_set_monitor(gtk_window_ptr(&gw), mon_ptr) };
+ }
+
/// Temporarily allow keyboard focus so a text field inside the island can be
/// typed in.
pub fn set_activating(win: &WebviewWindow, activating: bool) {
diff --cc windows/src-tauri/src/platform/windows.rs
index 22e25af5,fe4bcae2..79bc6a12
--- a/windows/src-tauri/src/platform/windows.rs
+++ b/windows/src-tauri/src/platform/windows.rs
@@@ -231,5 -234,5 +231,8 @@@ pub fn set_activating(win: &WebviewWind
/// 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)>) {}
+/// The cursor poll already parks itself with the island (island.rs): nothing to do.
+pub fn set_pointer_watch(_active: bool) {}
++
+ /// `set_position` already places a Win32 window on the right display.
+ pub fn pin_to_monitor(_win: &WebviewWindow, _x: i32, _y: i32) {}