Add inactive translucent always-on-top popup

This commit is contained in:
2026-09-12 13:50:50 +02:00
parent d585958d6d
commit 5f482a2865
6 changed files with 122 additions and 1 deletions

View File

@@ -61,6 +61,10 @@ Each bounded iteration must:
- [ ] Make popup close hide the window while the background process continues (code path added; desktop verification pending).
- [ ] Center the popup on the configured/active monitor.
- [x] Keep the X11 popup above other windows and apply 30% opacity while it is
inactive, returning to full opacity when focused (27 X11-feature tests and
Docker GTK/X11/package build, 2026-09-12); compositor behavior remains live
desktop evidence.
- [x] Preserve search query and surviving selection after refresh-triggering actions (17 core tests and Docker GTK/X11 build, 2026-09-10).
- [ ] Keep keyboard pause state synchronized with button and status text.
- [ ] Implement complete keyboard-first navigation and commands.

26
Cargo.lock generated
View File

@@ -153,6 +153,7 @@ dependencies = [
"anyhow",
"dirs",
"fs2",
"gdk4-x11",
"glib",
"gtk4",
"ksni",
@@ -446,6 +447,31 @@ dependencies = [
"system-deps",
]
[[package]]
name = "gdk4-x11"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c3e7380a9a206b170e1b52b5f25581406db816c68f4e7140dbef89a9e5b52ac"
dependencies = [
"gdk4",
"gdk4-x11-sys",
"gio",
"glib",
"libc",
]
[[package]]
name = "gdk4-x11-sys"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "070bd50a053f90d7fdf6be1d75672ea0f97c0e5da3a10dc6d02e5defcb0db32f"
dependencies = [
"gdk4-sys",
"glib-sys",
"libc",
"system-deps",
]
[[package]]
name = "generic-array"
version = "0.14.7"

View File

@@ -9,7 +9,7 @@ default-run = "clipbhoard"
[features]
default = []
x11 = ["dep:x11rb", "dep:x11-clipboard"]
gui = ["x11", "dep:gtk4", "dep:glib", "dep:ksni"]
gui = ["x11", "dep:gtk4", "dep:gdk4-x11", "dep:glib", "dep:ksni"]
[dependencies]
anyhow = "1.0"
@@ -25,6 +25,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
fs2 = "0.4"
gtk4 = { version = "0.9", optional = true }
gdk4-x11 = { version = "0.9", optional = true }
glib = { version = "0.20", optional = true }
ksni = { version = "0.2.2", optional = true }
x11rb = { version = "0.13", features = ["allow-unsafe-code", "xtest"], optional = true }

View File

@@ -174,6 +174,14 @@ fn build_window(
.default_height(420)
.child(&root)
.build();
let window_for_opacity = window.clone();
window.connect_realize(move |_| {
crate::platform::linux::x11_window::configure(&window_for_opacity);
});
let window_for_opacity = window.clone();
window.connect_is_active_notify(move |_| {
crate::platform::linux::x11_window::set_active_opacity(&window_for_opacity);
});
window.set_title(Some(&format!("Cliphoard — {}", config.global_shortcut)));
pause_button.set_tooltip_text(Some("Pause/resume recording: Ctrl+Alt+R"));
let window_for_close = window.clone();

View File

@@ -1,6 +1,8 @@
mod x11_clipboard;
mod x11_events;
mod x11_input;
#[cfg(feature = "gui")]
pub(crate) mod x11_window;
pub use x11_clipboard::{
ClipboardWorkerResult, X11Clipboard, X11ClipboardReader, X11ClipboardWorker,

View File

@@ -0,0 +1,80 @@
use gtk4::{prelude::*, ApplicationWindow};
use x11rb::{
connection::Connection, protocol::xproto::ConnectionExt as X11ConnectionExt,
wrapper::ConnectionExt as X11WrapperExt,
};
const ACTIVE_OPACITY: f64 = 1.0;
const INACTIVE_OPACITY: f64 = 0.30;
pub fn configure(window: &ApplicationWindow) {
set_active_opacity(window);
let Some(surface) = window.surface() else {
return;
};
let Some(surface) = surface.downcast_ref::<gdk4_x11::X11Surface>() else {
tracing::debug!("popup window is not backed by an X11 surface");
return;
};
let xid = surface.xid();
let Ok((connection, _)) = x11rb::connect(None) else {
tracing::warn!("could not connect to X11 to keep popup above other windows");
return;
};
let Ok(state_cookie) = connection.intern_atom(false, b"_NET_WM_STATE") else {
return;
};
let Ok(state) = state_cookie.reply() else {
return;
};
let Ok(above_cookie) = connection.intern_atom(false, b"_NET_WM_STATE_ABOVE") else {
return;
};
let Ok(above) = above_cookie.reply() else {
return;
};
if let Err(error) = connection.change_property32(
x11rb::protocol::xproto::PropMode::REPLACE,
xid as u32,
state.atom,
x11rb::protocol::xproto::AtomEnum::ATOM,
&[above.atom],
) {
tracing::warn!(%error, "could not mark popup as always on top");
}
let _ = connection.flush();
}
pub fn set_active_opacity(window: &ApplicationWindow) {
let Some(surface) = window.surface() else {
return;
};
let Some(surface) = surface.downcast_ref::<gdk4_x11::X11Surface>() else {
return;
};
let Ok((connection, _)) = x11rb::connect(None) else {
return;
};
let Ok(opacity_cookie) = connection.intern_atom(false, b"_NET_WM_WINDOW_OPACITY") else {
return;
};
let Ok(opacity) = opacity_cookie.reply() else {
return;
};
let value = if window.is_active() {
ACTIVE_OPACITY
} else {
INACTIVE_OPACITY
};
let scaled = (value * u32::MAX as f64).round() as u32;
if let Err(error) = connection.change_property32(
x11rb::protocol::xproto::PropMode::REPLACE,
surface.xid() as u32,
opacity.atom,
x11rb::protocol::xproto::AtomEnum::CARDINAL,
&[scaled],
) {
tracing::debug!(%error, "could not update popup opacity");
}
let _ = connection.flush();
}