The best way to control Claude Code, Codex and more from any computer or phone
fix(native): KDE SnapShot no longer loses the first reply from KWin (#36218)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Theo Browne committed
Nov 13, 2026 at 16:11 UTC
9d8998b436f7d81295386e4f6aa7012784aa86a6
2 files changed
+28
-22
native/kde-snap-shot/src/main.rs
+27
-17
@@ -71,10 +71,11 @@ struct Bounds {
71
height: u32,
72
}
73
74
-struct ScriptReply {
75
- owner: String,
76
- result: mpsc::SyncSender<String>,
77
-}
74
+const REPLY: &str = "/com/t3tools/KdeCapture";
75
+
76
+/// KWin's bus name and the channel of the script call in flight. `None` between calls.
77
+#[derive(Default)]
78
+struct ScriptReply(Option<(String, mpsc::SyncSender<String>)>);
79
#[zbus::interface(name = "com.t3tools.KdeCapture")]
80
impl ScriptReply {
81
fn reply(
@@ -82,7 +83,12 @@ impl ScriptReply {
83
value: &str,
84
#[zbus(header)] header: zbus::message::Header<'_>,
85
) -> zbus::fdo::Result<()> {
85
- if header.sender().map(|name| name.as_str()) != Some(self.owner.as_str()) {
86
+ let Some((owner, result)) = &self.0 else {
87
+ return Err(zbus::fdo::Error::AccessDenied(
88
+ "No script is running".into(),
89
+ ));
90
+ };
91
+ if header.sender().map(|name| name.as_str()) != Some(owner.as_str()) {
92
return Err(zbus::fdo::Error::AccessDenied("Not KWin".into()));
93
}
94
if value.len() > 64 * 1024 {
@@ -90,23 +96,29 @@ impl ScriptReply {
96
"Oversized window metadata".into(),
97
));
98
}
93
- let _ = self.result.try_send(value.to_owned());
99
+ let _ = result.try_send(value.to_owned());
100
Ok(())
101
}
102
}
103
104
+/// Serves the reply object from the start, so zbus waits for its method-call listener.
105
+/// A listener started after connecting can miss the first call from KWin.
106
+fn connect(builder: Builder<'_>) -> zbus::Result<Connection> {
107
+ builder
108
+ .method_timeout(DEADLINE)
109
+ .serve_at(REPLY, ScriptReply::default())?
110
+ .build()
111
+}
112
+
113
/// Scripts exist only for this operation. Unload even when evaluation/callback fails.
114
fn script(connection: &Connection, directory: &Path, body: &str) -> Result<String> {
115
let dbus = zbus::blocking::fdo::DBusProxy::new(connection)?;
116
let owner = dbus.get_name_owner("org.kde.KWin".try_into()?)?.to_string();
117
let (send, receive) = mpsc::sync_channel(1);
103
- connection.object_server().at(
104
- "/com/t3tools/KdeCapture",
105
- ScriptReply {
106
- owner,
107
- result: send,
108
- },
109
- )?;
118
+ let reply = connection
119
+ .object_server()
120
+ .interface::<_, ScriptReply>(REPLY)?;
121
+ reply.get_mut().0 = Some((owner, send));
122
let path = directory.join("window.js");
123
let name = format!("t3-capture-{}", std::process::id());
124
let destination = serde_json::to_string(
@@ -147,9 +159,7 @@ fn script(connection: &Connection, directory: &Path, body: &str) -> Result<Strin
159
let _: std::result::Result<bool, _> = scripting.call("unloadScript", &(&name,));
160
result
161
})();
150
- connection
151
- .object_server()
152
- .remove::<ScriptReply, _>("/com/t3tools/KdeCapture")?;
162
+ reply.get_mut().0 = None;
163
let _ = std::fs::remove_file(path);
164
result
165
}
@@ -336,7 +346,7 @@ fn capture(connection: &Connection, directory: &Path) -> Result<Option<Window>>
346
347
fn run() -> Result<()> {
348
let args: Vec<String> = std::env::args().collect();
339
- let connection = Builder::session()?.method_timeout(DEADLINE).build()?;
349
+ let connection = connect(Builder::session()?)?;
350
match args.get(1).map(String::as_str) {
351
Some("check") => {
352
check(&connection)?;
native/kde-snap-shot/src/transport_tests.rs
+1
-5
@@ -183,11 +183,7 @@ impl Fixture {
183
.unwrap()
184
.build()
185
.unwrap();
186
- let client = Builder::address(address.trim())
187
- .unwrap()
188
- .method_timeout(DEADLINE)
189
- .build()
190
- .unwrap();
186
+ let client = connect(Builder::address(address.trim()).unwrap()).unwrap();
187
Self {
188
daemon,
189
directory,